title: replacing system.out.println(class) in java
body: <p>I've got some classes which include toString functions which work very well as:</p>
  
  <p>snipped of declaration:</p>
  
  <pre><code>public String toString() {
          return "Port info: "+myPort.variable;
      }
  </code></pre>
  
  <p>snipped of main():</p>
  
  <pre><code>Port myPort;
  myPort.fillInfo();
  system.out.println(myPort);
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>"Port info: 123"
  </code></pre>
  
  <p>I'm trying to replace all my system.out.println(myPort) calls with myWindow.println(myPort) calls where myWindow contains:</p>
  
  <pre><code>public void println(String toPrint)
  {
      textArea.append(toPrint+"\n"); //or insert
  }
  </code></pre>
  
  <p>However, I'm getting:</p>
  
  <pre><code>The method println(String) in the type window is not applicable for the arguments (Port)
  </code></pre>
  
  <p>In other words, my declaration is expecting the String type, and I'm trying to pass it the Port type.</p>
  
  <p>Somehow, system.out.println() will take any class that's got a toString() declared.</p>
  
  <p>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?</p>