Fixing Java 8 compilation issues with type casting