2015-04-20 15:36:01 -07:00
|
|
|
|
//: generics/Manipulation.java
|
2015-05-29 14:18:51 -07:00
|
|
|
|
// <20>2015 MindView LLC: see Copyright.txt
|
2015-04-29 12:53:35 -07:00
|
|
|
|
// {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 =
|
2015-05-05 11:20:13 -07:00
|
|
|
|
new Manipulator<>(hf);
|
2015-04-20 15:36:01 -07:00
|
|
|
|
manipulator.manipulate();
|
|
|
|
|
}
|
2015-05-05 11:20:13 -07:00
|
|
|
|
} ///:~
|