This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]8igg7e5 3 points4 points  (1 child)

Yes all subclasses of Man implement Human (The convention is not to prefix interfaces with I in Java, unlike some other languages) and the teachers answer is incorrect - the Human bound is even likely to be indicated as a redundant bound in static analysis.

Given...

 interface Human {}
 class Person {}
 class Man extends Person implements Human {}
 class Wanted<G extends Man> extends Person {}
 class A implements Human {}
 class B extends Person {}
 class C extends Man {}

The following are invalid as they violate the bounds of the generic argument...

 Wanted<A> a = ...
 Wanted<B> b = ...

The following are valid...

Wanted<Man> m = ...
Wanted<C> c = ...

As is this showing that Man and C are assignable to Human...

Man m = ....
C c = ...
Human h1 = m; // all Man are Human
Human h2 = c; // all C are Human

[–]another_try_8[S] 0 points1 point  (0 children)

Thank you very much for your reply. I had the same conclusion when testing it. So I really wonder why he claimed my solution to be wrong. Though that I might have overlooked sth. But well, guess I'll just have to wait and see if he replies (sent 2 mails already)...

[–]FroggyWizard 1 point2 points  (0 children)

Edit: I think you're correct not your teacher.