title: Example of passing an uninitialized object as parameter in Java
body: <p>I just saw an constructor like this:</p>
  
  <pre><code> public class Test {
  
       private int x;
  
       public int getX(){
           return x; 
       }
  
       public Test(){ // Default constructor
           x= 0;
       }
  
       public Test(int x){ // Constructor with parameter
           this.x= x;
       }
  
       public Test(Test t){ // Copy-constructor   &lt;----This one!!!
           if (t!=null){
               this.x= t.getX();
           }  
       }
  } 
  </code></pre>
  
  <p><strong>I tried to imagine a situation where "t=null" could be the case.</strong> I tried this:</p>
  
  <pre><code>public class Fruit {
  
      public static void main(String[] args) {
  
          Test banane;
          Test jogurt = new Test(banane);
     }
  }
  </code></pre>
  
  <p>Nevertheless I was unable to compile as for"The local variable banane may not have been initialized"</p>
  
  <p>When I thought more about this it actually made sense for me. The compiler knows that the object and has not been initiliazed yet and complains about that. Since where unable to typecast a long to an object to make it look like a pointer/reference to an object, I cannot imagine a way to fool the compiler.</p>
  
  <p>Or is this just state of the art for the case that JVM ***** up. If so, is there a document about this from Oracle?</p>