OnJava8-Examples/generics/Manipulation.java

18 lines
446 B
Java
Raw Normal View History

2015-04-20 15:36:01 -07:00
//: generics/Manipulation.java
// {CompileTimeError} (Will not compile)
2015-04-20 15:36:01 -07:00
class Manipulator<T> {
private T obj;
public Manipulator(T x) { obj = x; }
// Error: cannot find symbol: method f():
public void manipulate() { obj.f(); }
}
public class Manipulation {
public static void main(String[] args) {
HasF hf = new HasF();
Manipulator<HasF> manipulator =
new Manipulator<HasF>(hf);
manipulator.manipulate();
}
} ///:~