Java Reference
In-Depth Information
Youcanassignmorethanoneupperboundtoatypeparameter,wherethefirstbound
isaclassorinterface,andwhereeachadditionalupperboundisaninterface,byusing
the ampersand character ( & ) to separate bound names. Consider Listing 3-53 .
Listing 3-53. Assigning multiple upper bounds to a type parameter
abstract class Shape
{
}
class Circle extends Shape implements Comparable<Circle>
{
private double x, y, radius;
Circle(double x, double y, double radius)
{
this.x = x;
this.y = y;
this.radius = radius;
}
@Override
public int compareTo(Circle circle)
{
if (radius < circle.radius)
return -1;
else
if (radius > circle.radius)
return 1;
else
return 0;
}
@Override
public String toString()
{
return "("+x+", "+y+", "+radius+")";
}
}
class SortedShapesList<S extends Shape&Comparable<S>>
{
 
Search WWH ::




Custom Search