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. SDCard explore on the device?

Hi,

I installed my application(.apk) onto SDCard in my Android G-1 HTC 1.5 version 
device through Eclipse. But in the device where i can see it? I don't see any 
SDCard explorer on the device. Anyone knows it?





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

2. kml in listview

I have to see the posts contained in a kml in a listview how does
google maps help (by opening the browser)
--~--~---------~--~----~------------~-------~--~----~

3. Why do I need requery() when I already have notifyDataSetChanged()

4. How to disable screen orientation change in code?

5. Location.getLastKnownLocation returns null

6. Location.getLastKnownLocation returns null

7. Pointers for a port to an OMAP device?