I am using .toString to return a string representation of an object, i.e.
jcb.engineMove(move.toString());
will produce e2e4.
What I am trying to do is to extract the text of this object (e2e4) as a string. After Googling I came across overriding the toString method so I came up with this:
@Override
public String toString() {
String s = "";
int newRank = getRank();
int newFile = getFile();
final Move move = new Move(rank, file, newRank, newFile);
s+="" + move;
return s;
}
My questions are fairly basic:
- is this the right approach
- How do I call this routine when trying to get the text of the object?