Results 1 to 4 of 4
  1. #1
    UAF
    UAF is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Default Couple of Generics questions

    Java Code:
    public class Try
    {
        public static void main(String[] prms)
        {
            ArrayList<ArrayList<A>> lla = new ArrayList<ArrayList<A>>();        
            ArrayList<ArrayList<B>> llb = new ArrayList<ArrayList<B>>();
            
            ArrayList<A> la = new ArrayList<A>();        
            ArrayList<B> lb = new ArrayList<B>();
                    
            
            stam(lla);        //compiler error
            stam(llb);        //compiler error
            
            stam2(lla);        
            stam2(llb);
                    
            stam3(lla);        
            stam3(llb);
            
            stam4(la);        
            stam4(lb);
            
            stam5(la);        
            stam5(lb);
        }
    
        static void stam(ArrayList<ArrayList<? extends A>> list){}
        
        static void stam2(ArrayList<? extends ArrayList<? extends A>> list){}
        
        static <T extends A> void stam3(ArrayList<ArrayList<T>> list){}
        
        static <T extends A> void stam4(ArrayList<T> list){}
        
        static void stam5(ArrayList<? extends A> list){}
    }
    
    class A
    {
        
    }
    
    class B extends A
    {
        
    }

    =======================================

    In the code above, the calls to stam() don't work.

    My main question is why the calls to Stam() don't work, while the calls to stam2() just below it do work.


    Also, if someone could clarify the difference between using wildcards and using T I'll be greatful.

  2. #2
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    This seems to me like a compiler bug to me.

  3. #3
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

  4. #4
    UAF
    UAF is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Default

    I read it, I still don't get it.
    Could you please try to exlpain in your own words.

    Why is
    Java Code:
    ArrayList<ArrayList<? extends A>>
    not good, and
    Java Code:
    ArrayList<? extends ArrayList<? extends A>
    good?

    I'm not trying to send something that extends ArrayList, I as sending one.

Similar Threads

  1. Couple more questions on JAR Files :S
    By Lil_Aziz1 in forum New To Java
    Replies: 13
    Last Post: 06-05-2010, 09:44 AM
  2. Couple questions about Java
    By theadolescent in forum New To Java
    Replies: 3
    Last Post: 05-19-2010, 03:13 AM
  3. Couple Questions on Thread
    By Lil_Aziz1 in forum Threads and Synchronization
    Replies: 5
    Last Post: 01-06-2010, 03:02 PM
  4. Couple of questions regarding threading
    By exernet in forum New To Java
    Replies: 1
    Last Post: 12-15-2009, 01:23 PM
  5. Couple of newbie questions
    By ananasman in forum New To Java
    Replies: 11
    Last Post: 11-21-2008, 12:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •