...
This compliant solution enforces type safety by changing the addToList()
method signature to enforce proper type checking.:
Code Block | ||
---|---|---|
| ||
class ListUtility { private static void addToList(List<String> list, String str) { list.add(str); // No warning generated } public static void main(String[] args) { List<String> list = new ArrayList<String> (); addToList(list, "42"); System.out.println(list.get(0)); } } |
...