Base class hijacks an interface(page 700)
- public class ComparablePet implements Comparable<ComparablePet>{
- @Override
- public int compareTo(ComparablePet arg) {
- return 0;
- }
- }
- /*The interface Comparable cannot be implemented
- more than once with different arguments:
- Comparable<ComparablePet> and Comparable<Cat> */
- //{CompileTimeError} (won't compile)
- class Cat extends ComparablePet implements Comparable<Cat>{
- @Override
- public int compareTo(Cat arg) {
- return 0;
- }
- }
- class RestrictedComparablePets extends ComparablePet
- implements Comparable<ComparablePet> {
- @Override
- public int compareTo(ComparablePet arg) {
- return 0;
- }
- }
- class Gecko extends ComparablePet{
- @Override
- public int compareTo(ComparablePet arg) {
- return 0;
- }
- }
- class TestInterface implements Comparable{
- @Override
- public int compareTo(Object o) {
- // TODO Auto-generated method stub
- return 0;
- }
- }
- public class reimplementInterface extends TestInterface implements Comparable{
- }
- class ComparableDirect implements Comparable{
- @Override
- public int compareTo(Object o) {
- // TODO Auto-generated method stub
- return 0;
- }
- }
- public class Test{
- public static void main(String args[]){
- new ComparableDirect().compareTo(new String(""));
- }
- }
- class ComparableIndirect extends ComparablePet{
- }
- public class Test2{
- public static void main(String args[]){
- new ComparableIndirect().compareTo(new ComparableIndirect());
- }
- }