H
Hatter Jiang
can i write a java class like this:
public class MyPrintJob<T extends Printable> extends T {
public void call() {
print("hello");
}
}
of course the code above cannot be compiled.
public interface Printable {
public void print(String string);
}
public class APrinter implements Printable {
public void print(String string) {
System.out.println("This is A printer:" + string);
}
}
public class BPrinter implements Printable {
System.out.println("This is B printer:" + string);
}
then when i can :
MyPrintJob<APrinter> aPrinter = new MyPrintJob<APrinter>();
aPrinter.call();
// outputs: This is A printer: hello
and :
MyPrintJob<BPrinter> bPrinter = new MyPrintJob<BPrinter>();
bPrinter.call();
// outputs: This is B printer: hello
public class MyPrintJob<T extends Printable> extends T {
public void call() {
print("hello");
}
}
of course the code above cannot be compiled.
public interface Printable {
public void print(String string);
}
public class APrinter implements Printable {
public void print(String string) {
System.out.println("This is A printer:" + string);
}
}
public class BPrinter implements Printable {
System.out.println("This is B printer:" + string);
}
then when i can :
MyPrintJob<APrinter> aPrinter = new MyPrintJob<APrinter>();
aPrinter.call();
// outputs: This is A printer: hello
and :
MyPrintJob<BPrinter> bPrinter = new MyPrintJob<BPrinter>();
bPrinter.call();
// outputs: This is B printer: hello