I am using .toString to return a string representation of an object, i.e.
jcb.engineMove(move.toString());
will produce e2e4.
What
To overwrite the toString() method is the common and right way to implement a custom textual representation of an object. You will find this procedure throughout literature and documentation.
In Java (like it is the case in other languages like C#) the toString()
method is defined in the object type which means that every object in Java has this method. If your custom object (which inherits from class object
) overwrites the toString()
method then your base class provides a new implementation of this method which hides/omits the toString()
method from the super class.
That means when you define a custom toString()
method in your custom class A a call to an instance of that type (say it's a) a.toString()
would result in calling your implementation.