Fixed casting issues.

Some concerns remain about strange casts with primitives:

boolean b = true;
Object o = b;
int x = cast<int>(o);