public class Box <T> {
private T data;
public Box(T data) {
this.data = data;
}
public T getData() {
return this.data;
}
}
Box box = new Box<>("My String"); // Raw type box
String s2 = (String) box.getData(); // No incompatible type error
String s1 = box.getData(); // Incompatible type error
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter