I've got some classes which include toString functions which work very well as:
snipped of declaration:
public String toString() {
return "Port info: "+myPort.variable;
}
snipped of main():
Port myPort;
myPort.fillInfo();
system.out.println(myPort);
output:
"Port info: 123"
I'm trying to replace all my system.out.println(myPort) calls with myWindow.println(myPort) calls where myWindow contains:
public void println(String toPrint)
{
textArea.append(toPrint+"\n"); //or insert
}
However, I'm getting:
The method println(String) in the type window is not applicable for the arguments (Port)
In other words, my declaration is expecting the String type, and I'm trying to pass it the Port type.
Somehow, system.out.println() will take any class that's got a toString() declared.
How does system.out.println take any class and print it out, and run its toString() method if it exists? And, more to the point, how can I replicate this functionality for my own println() function?