Fix Java 8 builds

Java 8 changes type inference and checking rules, needing a new cast.