-1

If I define the following types for a class:

class SomeClass<A extends InterfaceA, B extends InterfaceB, C extends B>

While InterfaceB extends InterfaceA. B also extends A but there I can’t declare that.

When casting an object of type C to any of [ B, InterfaceA, InterfaceB ], there isn't any warning (as expected).

But when casting C to A an unchecked cast warning raises. Why?

Noam
  • 1,018
  • 7
  • 18

2 Answers2

2

Because A is not in C's inheritance chain.

 InterfaceA
 /        \
A      InterfaceB
       /
      B
     /
    C
Dave Drake
  • 323
  • 2
  • 12
  • obviously, I was so into this issue that I didn't notice. My real problem is that I can't do something like that: `C extends B&A`. Thanks anyway – Noam Feb 01 '18 at 15:22
1

Because C extends B, which implements InterfaceB, which in turn extends InterfaceA. C doesn't extend A.

Linora
  • 10,418
  • 9
  • 38
  • 49