inconvertible types when casting

I was unlucky enough to hit a compiler bug, such that Eclipse IDE passes compilation, but it failed on my server using ant with Sun’s compiler. From the bug report it happens to JDK6 and will only be fixed in JDK7, so in the meantime I read of 2 workarounds that work.

1. Up-cast to an Object so that the down-cast become compiler-legal.


2. Use the Class.cast() method.

ChildType.class.cast( getParentType() );


  1. Pramod Reddy Chinthapalli said,

    December 2, 2011 at 5:25 pm


  2. Michael James said,

    June 24, 2012 at 4:51 pm

    Bless you, my friend! You just solved my fatal problem 🙂

  3. Aaron said,

    October 21, 2012 at 4:00 pm

    Thank you!!!! Spent hours trying to find out what was wrong with my code!!

RSS feed for comments on this post · TrackBack URL

Leave a Comment