问题
Why can't I add any object here , I was hoping I would be allowed to add any kind of object in such a list.
List<?> l = new ArrayList<Object>();
l.add(new Object());
l.add(new String("hello"));
回答1:
Why not just:
List<Object> l = new ArrayList<>();
l.add(new Object());
l.add(new String("hello"));
来源:https://stackoverflow.com/questions/24756464/unable-to-add-object-to-generic-list-using-wildcard