mardi 30 avril 2019

Using java generic types for type transformation

I have an Object o that can be casted to type A and type B.

I need a function transformForType(Type t, Object o) that takes a type, lets say A or B and checks if o its that type and process it to transform it.
The usage of the function would be something like that: B result = tranformForType(B.class, o);


My question is whats the way to define the tranformForType function, and if its posible whats the best way using generic types.
Regards.





Aucun commentaire:

Enregistrer un commentaire