In the method below, do I need to use <String> as it is in the method declaration of the second example of the same method?
Tony Morris
Ranch Hand
Joined: Sep 24, 2003
Posts: 1608
posted
0
You don't need to. You might return a List<?> or a List<? super String>. There isn't much point to returning a List<? extends String> even though the compiler will permit it. It's all up to the definition of the contract that you are providing to your clients.
Originally posted by Jesper de Jong: Note that java.lang.String is a final class (you can't subclass it), so List<? extends String> or List<? super String> isn't necessary.
Just use List<String> as in your second version of the method.
List<? extends String> makes no sense. List<? super String> may certainly be sensible in some given context. I said that already.