存在两个集合对象ArrayList<A> a
和ArrayList<B> b
a和b对象经过序列化和反序列化之后得到的都是Object对象,此时如何判断Object对象具有的泛型种类进行强制类型转化,对a和b进行不同的业务处理。
怪我咯2017-04-17 17:50:56
a and b are both ArrayLists, and their generic types cannot be obtained at runtime. You can try to take out an element from a or b, and then use instanceof to determine the type of the element, and then cast it.
迷茫2017-04-17 17:50:56
In Java, generics only exist during the compilation phase, which means that generics will be erased during runtime.
Then deserialization is all ArrayList. You can convert it into any ArrayList<T> before compiling. No judgment is made during runtime.