This question has been baffling to me; below is an example.
public interface UserInterface{
public String make_nickname();
}
public class UserInfo implements UserInterface{
private String name;
private String nickname;
public String make_nickName(){
this.nickname = this.name + "ish";
return this.nickname;
}
}
That given, I'm calling any instances that implements UserInterface
like such:
public void showNickName(<T extends UserInterface>T user){
system.out.println(user.make_nickname());
}
T
is used to denote a (generic) implementing class of UserInterface
.
But here I called it as <T exnteds UserInterface>
which as far as I know implies T is an subclass(not implementing class) of UserInterface
.
Is this legitimate grammar of calling instances of UserInfo
?
Somehow above code seems to work for me.
Any feedback would be welcome.
As mentioned in the Java tutorial on bounded type parameters:
In generics context, extends is used in a general sense to mean either "extends" (as in classes) or "implements" (as in interfaces).