Home »
Scala language
Comments in Scala
Scala comments: Comments are a very important part of programming. In Scala comments are Java-like. In this Scala tutorial on comments, we will learn how to use comments with working code.
Submitted by Shivang Yadav, on July 14, 2019
Scala comments
Comments are things that are readable by the programmer. They are added to the code to add an explanation about the source code. Commenting on a program to make it easier to understand by the programmer.
In Scala also comments are available. The comments in Scala are same as C++, Java and many other popular programming languages.
There are two types of comments that can be added to a program:
- Single-line comment
- Multiline Comment
1) Single line comment
It is the comment that has a span of an only single line. The line in which comment is started is commented.
Syntax:
// Single line code to be commented...
2) Multiline comment
A multiline comment can span up to many lines based on its end literal. A multiline comment starts and ends with a literal and all the code inside that literal is treated as a comment.
Syntax:
/*
Multiline
Code to be commented
*/
Example for Scala comments
object MyClass {
def main(args: Array[String]) {
//printing Hello world! - this is single line comment
print("Hello world!");
/*
This is multiline comment -
Here, we are printing Hi friends!
*/
print("Hi friends!");
}
}
Output
Hello world!Hi friends!