OnJava8-Examples/generics/ClassCasting.java

17 lines
469 B
Java
Raw Normal View History

2015-04-20 15:36:01 -07:00
//: generics/ClassCasting.java
2015-05-29 14:18:51 -07:00
// <20>2015 MindView LLC: see Copyright.txt
2015-04-20 15:36:01 -07:00
import java.io.*;
import java.util.*;
public class ClassCasting {
@SuppressWarnings("unchecked")
public void f(String[] args) throws Exception {
ObjectInputStream in = new ObjectInputStream(
new FileInputStream(args[0]));
// Won't Compile:
// List<Widget> lw1 =
2015-05-18 23:05:20 -07:00
// List<>.class.cast(in.readObject());
2015-04-20 15:36:01 -07:00
List<Widget> lw2 = List.class.cast(in.readObject());
}
} ///:~