Fixed annoying Java casting issue