As we all know the Generics about Java Collections that E or a wildcard ? is required to instantiate the allowed contents / objects in a particular collection.
My question is there a way we could know the wildcard or object of a particular collection from the code below?
Object inbound = java.io.ObjectInputStream().readObject();
if(inbound instanceof List<?>) {
// know `?.getClass()`
}
You can only find the type parameters if
inboundis a class that defines its type parameters in a type declaration. For example, suppose you serialized an instance ofNodeListthat was declared like this:Then when you deserialize it, you can do this: