aspose file tools*
The moose likes Java in General and the fly likes Generics Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Generics Question" Watch "Generics Question" New topic
Author

Generics Question

henri henri
Ranch Hand

Joined: Oct 03, 2005
Posts: 115
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
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.


Tony Morris
Java Q&A (FAQ, Trivia)
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14338
    
  22

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generics Question