Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jdt-core-dev] [1.5] Generic methods now supported




In my previous example, I forgot to mention that the type inference
involved for generic methods is also able to recurse in supertypes.
If you pay attention to the testcase, you'll observe that #sort is
expecting a List<T>, where it is supplied a LinkedList<String>.
Since LinkedList is defined as:

      public class LinkedList<E>
          extends AbstractSequentialList<E>
          implements List<E>, Queue<E>, ... etc ...

LinkedList<String> implements List<String>, which is then matching List<T>
given 'T' is substituted by 'String'.

Under the same rules, you could even supply an instance of C as an argument
to #sort, where C is defined as:
      public class C extends LinkedList<String>
which would result in 'T' associated with 'String', as well.



                                                                           
             Philippe P                                                    
             Mulet/France/IBM@                                             
             IBMFR                                                      To 
             Sent by:                  jdt-core-dev@xxxxxxxxxxx            
             jdt-core-dev-admi                                          cc 
             n@xxxxxxxxxxx                                                 
                                                                   Subject 
                                       [jdt-core-dev] [1.5] Generic        
             04/15/2004 01:29          methods now supported               
             AM                                                            
                                                                           
                                                                           
             Please respond to                                             
               jdt-core-dev                                                
                                                                           
                                                                           








I just released changes which allow Cheetah to digest more evolved generic
method scenarii.

   public class X {
       public static void main(String [] args) {
           java.util.Collections.sort(new java.util.LinkedList<String>());
       }
   }

fyi, the method Collections#sort is spec'ed in a nasty way, as the bound
for variable T is referencing itself,
which makes the job for checking the bound of inferred type (String in
example above) a bit tricky.

   public static <T extends Comparable<? super T>> void sort(List<T> list)

We will sanity check the Cheetah, and post an updated preview shortly if
successful.


_______________________________________________
jdt-core-dev mailing list
jdt-core-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/jdt-core-dev




Back to the top