My compiler was not able to deal these casts by itself.

After cloning this repository, I ran ant and in returning lines of these methods I got this exception:

"type parameters of <T>T cannot be determined; no unique maximal instance exists for type variable X with upper bounds..."

I don't know why it is happening, but after some googling I found out that this is a common error. Well, forcing the cast (unsafe) when returning seems to correct it.