Unable to add object to generic list using wildcard [duplicate]
问题 This question already has answers here : Can't add value to the Java collection with wildcard generic type (4 answers) Closed 5 years ago . 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