mirror of
https://github.com/Jueee/effective-Java.git
synced 2026-09-04 05:42:47 +08:00
24 lines
659 B
Java
24 lines
659 B
Java
package com.jueee.item26;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class Item26Example02 {
|
|
|
|
// Fails at runtime - unsafeAdd method uses a raw type (List)!
|
|
public static void main(String[] args) {
|
|
List<String> strings = new ArrayList<>();
|
|
|
|
// The method unsafeAdd(List<Object>, Object) in the type Item26Example02 is not applicable for the arguments (List<String>, Integer)
|
|
// unsafeAdd(strings, Integer.valueOf(42));
|
|
|
|
String s = strings.get(0);
|
|
System.out.println(s);
|
|
}
|
|
|
|
private static void unsafeAdd(List<Object> list, Object o) {
|
|
list.add(o);
|
|
}
|
|
|
|
}
|