2

Is there any difference in below two?

Code:

List<? extends Object> ls = new ArrayList<String>();
List<?> ls1 = new ArrayList<String>();
Juns
  • 511
  • 1
  • 5
  • 10

1 Answers1

2
List<? extends Object>

and

List<?>

Both are same. Because collections doen't allow primitives and only Classes ,in java every Class implicitly extends Object.

You can see the difference If you write List<? extends MyOwnParentClass>.

But with Object, you won't get any extra benefit/loss here.

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307