Fix Class Cast Exception on some generics types