1

In java we cannot assign variable like

List<Object> list = new ArrayList<String>();

But we can assign like

List l = new ArrayList<String>();

The first one I know that if super class reference would have been allowed then user could be able to add instance of different class have same super type and it would cause issue while accessing element.

But second case i am not able to understand why it is allowed.

Can anybody please explain it.

Vikram Singh
  • 924
  • 1
  • 9
  • 23

0 Answers0