List<Object> list = new ArrayList<String>();
This is giving me an error
ArrayList<String>
cannot be converted toList<Object>
List<Object> list = new ArrayList<String>();
This is giving me an error
ArrayList<String>
cannot be converted toList<Object>
You can add any object to a List<Object>
, but you should only be able to add String
objects to a List<String>
. Therefore you cannot assign a List<String>
to a List<Object>
variable.
If your List
should only hold String
objects, change its type :
List<String> list = new ArrayList<String>();