Add casts to fix some compilation problems

javac/intellij wanted the explicit casts