Java 6 compatibility for casting

With this fix, project compiles also with Java 6