← Back to Scala Course | Chapter 1: Setup & Basics | Lesson 8 of 8

Comments

In this page:

  1. Comments

Comments

A // starts a single-line comment in Scala, and /* ... */ wraps a multi-line comment block. Scaladoc comments, written as /** ... */, are used to generate API documentation and can appear above classes, objects, and methods. Comments should explain non-obvious reasoning, not restate what the code already makes clear.

Note: /** ... */ (double-star) Scaladoc comments are recognized by documentation-generation tools, unlike plain /* ... */ comments.

Example: Comments

markup
object Main extends App {
  // This is a single-line comment
  val x = 10 // inline comment after code

  /* This is a
     multi-line comment block */

  /** Scaladoc comment describing this value. */
  val y = 20

  println(x + y)
}
🔒

Chapter Quiz — Complete all 8 topics to unlock

0/8 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.