继续问土问题# Java - 爪哇娇娃
r*w
1 楼
怎样能够得知一个object的class呢?
就是说我有一个object
我要on the fly new 一个deep copy of it...
so i have to call the related constructor...
but I want the implementation quite generic...
i know i can do
if obj instanceof Class1
then new_obj=new Class1(obj)
else if obj instanceof Class2
then new_obj=new Class2(obj)
etc...
any other more elegant solution?
就是说我有一个object
我要on the fly new 一个deep copy of it...
so i have to call the related constructor...
but I want the implementation quite generic...
i know i can do
if obj instanceof Class1
then new_obj=new Class1(obj)
else if obj instanceof Class2
then new_obj=new Class2(obj)
etc...
any other more elegant solution?