공부
[Java] cast object by generic
승가비
2021. 7. 24. 23:53
728x90
public static <T> T convertInstanceOfObject(Object o, Class<T> clazz) {
try {
return clazz.cast(o);
} catch(ClassCastException e) {
return null;
}
}
https://stackoverflow.com/questions/14524751/cast-object-to-generic-type-for-returning
Cast Object to Generic Type for returning
Is there a way to cast an object to return value of a method? I tried this way but it gave a compile time exception in "instanceof" part: public static T convertInstanceOfObject(Object o...
stackoverflow.com
728x90