01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
package types.point6;
import java.awt.Color;
interface Colored {
Color getColor();
}
interface Point {
double getX();
double getY();
}
final class CartesianPoint implements Colored, Point {
/* ... */
}
final class PolarPoint implements Colored, Point {
/* ... */
}
class Main {
private Main() {}
public static <T extends Point & Colored> void printColoredPoint(T cp) {
System.out.println(cp.getX());
System.out.println(cp.getY());
System.out.println(cp.getColor());
}
public static void main(String[] args) {
printColoredPoint(new CartesianPoint(0,0,Color.RED));
printColoredPoint(new PolarPoint(0,0,Color.RED));
}
}
|