Книга: Learn Scala for Java Developers
Назад: Scala’s Class Hierarchy
Дальше: Language Features

ScalaDoc

Scala has ported the idea of JavaDoc and creatively called it ScalaDoc. Adding ScalaDoc to your Scala source works similarly to adding JavaDoc, and is done with markup in comments. For example, the following fragment in source code:

  /** Returns `true` if this value is equal to x, `false` otherwise. **/   def ==(x: Byte): Boolean 

…can be turned into the following fragment in HTML:

Fig. 1.8. Embedded ScalaDoc markup gets rendered in HTML.

Fig. 1.8. Embedded ScalaDoc markup gets rendered in HTML.

To see the documentation for the Scala API, head over to http://scala-lang.org/documentation. You’ll notice it is broadly similar to JavaDoc. You can see the classes along the left; they’re not grouped by package like in JavaDoc but they’re clickable to get more information.

 

Fig. 1.9. The basic ScalaDoc for `Char`.

Fig. 1.9. The basic ScalaDoc for Char.

A neat feature of ScalaDoc is that you can also filter the content. For example, you can show only methods inherited from Any.

If you’re interested in the hierarchy of a class, you can look at its super- and subtypes. You can even see a navigable diagram of the type hierarchy. For example, the type hierarchy diagram for Byte shows it is a subtype of AnyVal, and you can navigate up through the hierarchy by clicking on the diagram.

Fig. 1.10. ScalaDoc showing the type hierarchy diagram.

Fig. 1.10. ScalaDoc showing the type hierarchy diagram.

Назад: Scala’s Class Hierarchy
Дальше: Language Features