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. what is Third party Apllication Server (C2DM server)?

Hey ,

I am done with the registration n i got the registration ID too...now
what is actually Third Party Application server..i Have js rough idea
n how can i start with the coding.Please help me guyz..
Thanks

-- 
.

2. OT: Microkia today? Wow, looks they're done

Scanning the news, stock markets and forums this morning and there
seems virtually universal disdain for Elop's Microkia deal... Geez
Louise looks like Elop's taking advantage of Nokia's weak moment to
hijack them and drive his own agenda. Layoffs in Finland... it doesn't
take rocket science where this is going.

-- 
.

3. Can an app get invoked on both mime-type *and* file extension?

4. ImageButton with rounded corners and no padding

5. Do XML Request if certain time elapsed

6. Best practice for when to go get data in a Fragment lifecycle?

7. Official Specs + Video Hands On Galaxy S II dan Galaxy Tab II