At line 12,compiler is infering E(for myMethod) as a String so according to the declaration the return type would become List<? super String> which means on invoking myMethod you are getting a returned list having type List<? super String>(during compile time).and what are you trying on line 12 is some thing like this:
List<CharSequence> = List<? super String> --------- <1>
if it were allowed then type safety would break as here it would be so easy to put a object in List<CharSequence>.
let's see the captured types for List<? super String> they are
List<Object>,List<Serializable>,List<Comparable<String>> and List<CharSequence>
so as per the capturing if <1> is allowed then it is easy to say these:
List<CharSequence> = List<Object> havoc! type safety broken(here it is too easy to put objects in list of charsequence)
List<CharSequence> = List<Serializable> ....and so on
you may be thinking then why the compiler allow you to return list "out".because List<? super String> = List<CharSequence> is valid as the List<CharSequence> is a subclass of List<? super String>(holds the
is a relationship),but the converse is not true.
for the compilation change line 12 to:
but it is not a good idea to use wild
cards in return type as the users of this method have to use it every time in their code on each call(you can see the same thing in your code).
Hope it helps!
Kind regards,
Praveen.