Java Guru needed -- compiler bug?

by Zsolt Vasvari » Fri, 20 May 2011 16:50:55 GMT


Sponsored Links
 private void method(Collection<String> s)
    {
        // Nothing
    }


    private void caller()
    {
       // Complies fine
        Collection<String> s = Collections.emptyList();
        method(s);

       // Doesn't compile -- gives error message
       // The method method(Collection<String>) in the type Import is
not applicable for the arguments
       //  (List<Object>)
        method(Collections.emptyList());
    }


What's going on here?   The two statements look identical to me...

-- 



Re: Java Guru needed -- compiler bug?

by Nikolay Elenkov » Fri, 20 May 2011 16:57:01 GMT


 


I'm not going to pretend to be a guru, but here goes :)

It's a generic method:

public static final <T> List<T> emptyList()

In the second call there is no way to determine the type of the generic
parameter, so you get a list of Object.

-- 


Sponsored Links


Other Threads

1. how to build the sample code from command line?

All the tutorials have been talking about building sample code from
Eclipse. I wonder if there is an easy way to build them from command
line.

It is not obvious how to achieve this with activityCreator.py script.

Cheers.

Jun
--~--~---------~--~----~------------~-------~--~----~

2. About Simple Talk

Hi,


   I have a gmail account.can i use that account(username and password ) in
xmpp settings?


Thanks
judy

--~--~---------~--~----~------------~-------~--~----~

3. webservice using ksoap2 in android

4. How to use a content provider created by some other app

5. I want to horizontally scroll a LinearLayout area

6. How to access GridView Elements individually

7. use of Handler.post