-1

I have just seen this code and I cannot see what is the benefit of defining a class in this way. Can anyone explain me why/when we use this notation?

At first I thought that an instance of ClassW would allow you to access methods from ClassB and ClassC but I see it doesn't. It is just a notation... but why?

class ClassW extends ClassZ {
}

abstract class ClassZ extends ClassA<ClassB, ClassC> {
}

class ClassA<B extends ClassB, C extends ClassC> {
    B b;
    C c;
}

abstract class ClassB {     
    public abstract void isB();     
}

abstract class ClassC {     
    public abstract void isC();     
}
Dennis Meng
  • 5,109
  • 14
  • 33
  • 36
daniel sp
  • 937
  • 1
  • 11
  • 29

1 Answers1

0

It means that B can be ClassB or any subtype of ClassB, and C can be ClassC or any subtype of ClassC. So you are specifying that is what you allow as the types B and C.

You can find some additonal good answers here

Community
  • 1
  • 1
pln
  • 1,108
  • 9
  • 13