Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to interpret and use generic vector?

Can any body explain this generic vector Vector<? super Object> list = ... and where to use it?

like image 592
itro Avatar asked Dec 19 '25 09:12

itro


1 Answers

Here you are defining the lower bound of your unknown object ?. So the Vector<? super Object can contain only Object and any super class of Object. But since Object does'nt have a super class it has no sense. It behaves same as Vector<Object>.

Refer this sample.

The counterpart for this is upper bound Vector<? extends Object> where you can add any object that extends Object.

You should be able to avoid using Object as the generic type is most cases.

like image 158
basiljames Avatar answered Dec 20 '25 22:12

basiljames



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!