0

In this basic example

String str = "hola";
Object o;

o = str; // it's OK

List<String> listado = new ArrayList<String>();
List<Object> listResult;

listResult = listado; // it's WRONG

why the cast to the superclass works in the first case but doesn't work when working with Lists? (It gives a Type mismatch: cannot convert from List< String> to List< Object>)

Álvaro
  • 1,351
  • 1
  • 10
  • 14

0 Answers0