Adds generic type information where possible

This suppresses most warnings in the code, and makes it more strict.

There are some unchecked type casts, but by the nature of Java and this library purpose, no choice...