展开全部
输入一个Object类型的数据 和 转型的类型的话可以实现,比如public static T get(Object o,Class clazz)
当然 T f1(Object o,T c){ 也行的 只是需要通过c获得一次636f70793231313335323631343130323136353331333337396165类的Class,public static T get(Object o,Class clazz){
if(clazz!=null){
if(clazz.isInstance(o))
return clazz.cast(o);
else
throw new RuntimeException(o +" is not a "+clazz.getName());
}
return null;
}
public static T get(Object o,T t){
Class clazz=(Class) t.getClass();
if(clazz!=null){
if(clazz.isInstance(o))
return clazz.cast(o);
else
throw new RuntimeException(o +" is not a "+clazz.getName());
}
return null;
}