steps.annotation
Members list
Type members
Experimental classlikes
A macro annotation that automatically generates a custom toString method for a class.
A macro annotation that automatically generates a custom toString method for a class.
The @toString annotation can be applied to a class, object, or trait. When applied, it overrides the toString method to include the class name and the values of all fields marked as ParamAccessor.
If the class already defines or overrides the toString method, the annotation will emit a warning indicating that the annotation is not necessary. The existing toString method will remain unchanged.
Example usage:
@toString
class MyClass(val a: Int, val b: String)
val instance = MyClass(1, "hello")
println(instance.toString) // Output: MyClass(1, hello)
The generated toString method produces output in the format: ClassName(field1, field2, ...).
Attributes
- Note
-
This annotation requires Scala's
experimentalflag to be enabled, or it can be used within a scope marked as experimental (i.e., usingimport scala.annotation.experimental). This is necessary because it relies on experimental macro annotation features. - Experimental
- true
- Supertypes
-
trait MacroAnnotationtrait StaticAnnotationclass Annotationclass Objecttrait Matchableclass AnyShow all