java - 使用泛型的集合对象序列化之后,如何判断反序列化后Object的泛型?
伊谢尔伦
伊谢尔伦 2017-04-17 17:48:56
0
2
736

存在两个集合对象ArrayList<A> aArrayList<B> b

a和b对象经过序列化和反序列化之后得到的都是Object对象,此时如何判断Object对象具有的泛型种类进行强制类型转化,对a和b进行不同的业务处理。

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(2)
刘奇

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.

迷茫

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template