title: Automatic type conversion in Java?
body: <p>Is there a way to do automatic implicit type conversion in Java? For example, say I have two types, 'FooSet' and 'BarSet' which both are representations of a Set. It is easy to convert between the types, such that I have written two utility methods:</p>
  
  <pre><code>/** Given a BarSet, returns a FooSet */
  public FooSet barTOfoo(BarSet input) { /* ... */ }
  
  /** Given a FooSet, returns a BarSet */
  public BarSet fooTObar(FooSet input) { /* ... */ }
  </code></pre>
  
  <p>Now say there's a method like this that I want to call:</p>
  
  <pre><code>public void doSomething(FooSet data) {
      /* .. */
  }
  </code></pre>
  
  <p>But all I have is a <code>BarSet myBarSet</code>...it means extra typing, like:</p>
  
  <pre><code>doSomething(barTOfoo(myBarSet));
  </code></pre>
  
  <p>Is there a way to tell the compiler that certain types can automatically be cast to other types? I know this is possible in C++ with overloading, but I can't find a way in Java. I want to just be able to type:</p>
  
  <pre><code>doSomething(myBarSet);
  </code></pre>
  
  <p>And the compiler knows to automatically call <code>barTOfoo()</code></p>