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. Passing pointer to AsyncTask that changes GUI to onRetainNonConfigurationInstance?

Good morning,

I'm a little confused how to correctly handle tasks (AsyncTask) when
the screen orientates.

The documentation states that the object passed to
onRetainNonConfigurationInstance should have no refererence to the
destroyed activity/context. When i pass a pointer to a AsyncTask it
shouldn't have such a reference.

But in the AsyncTask onPostExecute() method (which is executed in the
UI thread) the result of the task should be displayed in the fields of
a activity.

How can i display the result of a AsyncTask in a activity when i may
not use anything that references to the destroyed activity?

For example i can't pass my EditBox to the constructor of the
AsyncTask, because it is a reference to the activity that will be
destroyed, but i do want to put the result of the task in that
EditBox ;-)

I buzzles me.

One solution comes in mind and that is to save the pointer to the task
in onRetainNonConfigurationInstance() and restore it in onCreate().
Then call a method on the task class and pass a pointer to the new
EditBox. But it isn't 100% save, cause while the screen is rotating
(things are destroyed/created) the task might finish and cause
unpredictable results.

Can anybody give me advice on this subject?

Kind regards,
Twan
--~--~---------~--~----~------------~-------~--~----~

2. Where do i put 45 MB Audio Files.

> I am new to android and i need to play list of audio files in my

Download them off the Internet and store them on the SD card. The
Environment class has a method that can tell you where the SD card is
located.


Use the aforementioned Environment class, build a path, and access the files.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 2.0 Available!



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

3. which junit to use when creating reusable library for Android apps?

4. sleep in Android Bluetooth event thread

5. setText for EditText is not working in 1.5

6. AndCooper Build Tool Release

7. Internal JVM memory questions