aspose file tools*
The moose likes Beginning Java and the fly likes Try to understando generic methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Try to understando generic methods" Watch "Try to understando generic methods" New topic
Author

Try to understando generic methods

André Asantos
Ranch Hand

Joined: Nov 23, 2009
Posts: 234
Does anybody get to interpret this following code: -> public static <T extends Comparable<? super T>> void sort(List<T> list) ?


André AS
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

The method accepts a generic list of which the type T must implement (the generic type definition doesn't know implement only extend) Comparable. But the type of Comparable must be T or a super class of T.

Example:


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Virendrasinh Gohil
Ranch Hand

Joined: Jun 09, 2004
Posts: 46
André Asantos wrote: Does anybody get to interpret this following code: ->

This says, the sort method accept list of Ts where T must implement comparable interface. Later part actually defined the type of Comparable interface. It says, the comparable interface should be of type of it's base class of current class.

Please see the code below for better understanding.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Try to understando generic methods