ok.. given the following:
The question is
Given that CharSequence is an interface implemented by String and StringBuilder which of the following can be inserted at insert here to compile and run without error
One of the answers is:
s.toString();
According the API the signature of toString() is
public
String toString()
which means that object returned by such a call is a String object which extends CharSequence and thus meets the requirements of <S extends CharSequence>
However this is the wrong answer..
Why? S has to extend CharSequence however if I declare a type S that extends CharSequence... my input can be a StringBuilder, but my return type can be a String ... they both fit the requirement.. or it is that S has to be the same type S for all s thus the class of the input and the output in this case must be an S??? Does that follow
polymorphism rules? can s be a subtype of S as long as IS-A S is true?
I dunno.. loosing hope of passing this
test.