title: Defining a type cast in Java
body: <p>I want to define a type cast from an arbitrary type to a primitive data type in Java. Is it possible to define a cast from one arbitrary type to another arbitrary type?</p>
  
  <pre><code>public class Foo{
      //methods, constructor etc for this class
      ...
      //make it possible to cast an object of type Foo to an integer 
  }
  //example of how an object of type foo would be cast to an integer
  public class Bar(){
      public static void main(String[] args){
          Foo foo1 = new Foo();
          int int1 = (int)foo1;
          System.out.println(int1+"");
      }
  }
  </code></pre>