Java 6 compatibility for casting