title: Same multiple downcasts in equals; will they be optimised?
body: <p>I tend to write my equals method in Java as a one liner...</p>
  
  <pre><code>class Test {
     private String a = "";
     private Integer b = Integer.MIN_VALUE;
     private Long c = Long.MIN_VALUE;
  
     public Test(final String a, final Integer b, final Long c) {
         this.a = a;
         this.b = b;
         this.c = c;
     }
  
     @Override
     public boolean equals(final Object obj) {
          return obj instanceof Test &amp;&amp; ((Test) obj).a.equals(this.a)
            &amp;&amp; ((Test) obj).b.equals(this.b)
            &amp;&amp; ((Test) obj).c.equals(this.c);
     }
  }
  </code></pre>
  
  <p>As you can see, in this approach I downcast the Object instance to Test instance many times. My question is, will it be optimised by the compiler so there will be a single downcast instead of three like if I wrote my equals method like this?</p>
  
  <pre><code> public boolean equals(final Object obj) {
       if (obj instanceof Test) {
           final Test test = (Test) obj;
           return test.a.equals(this.a) &amp;&amp; test.b.equals(this.b)
             &amp;&amp; test.c.equals(this.c);
       } else {
           return false;
       }
   }
  </code></pre>
  
  <p>It is not a duplicate of the <a href="https://stackoverflow.com/questions/2165246/is-there-any-runtime-cost-for-casting-in-java">question</a> in comment, because I am interested here in brevity of the implementation of the equals method (6 lines against 3) but not at cost of a performance degradation. In the other question the difference is one line.</p>