Java: how to deal with generic heterogeneous containers?

What (and why) is a better way to deal with heterogeneous containers (i.e. database cursors with strings, integers, etc.):

Vector<?>

or

Vector<Object>

You can replace the vector with any other collection, which is just an example

Solution

I'm not sure what you're comparing Trying to create a vector

java.util.Vector<?> v = new java.util.Vector<?>();

Get error, unable to instantiate vector type

If you use Being in the parameter list (without the super keyword) means that you cannot insert anything into the collection If you use < Object > then you can insert and delete things

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>