toString

The method every object has that returns a text description of it, used when you print the object.

In more detail

The default from Object prints the class name and an unhelpful number. Records generate a readable version listing each component, such as Point[x=2, y=3].

Example

System.out.println(new Point(2, 3));  // Point[x=2, y=3]

Related terms

Taught in

References

Certification courses