Generics against intuitions

Hope all of you would know the Generics in java 5. If so, can you try to locate the error in the below program, that leads to the follwing compilation error

– The method testMethod(List<Map<String,String>>) in the type OverloadingTest is not applicable for the arguments  (ArrayList<HashMap<String,String>>)

public class OverloadingTest {

public void testMethod(List< Map<String,String>>oneArg){

                                System.out.println(“In list of Map method”);

                }

                public static void main(String[] args) {

                                OverloadingTest test = new OverloadingTest();

                                HashMap<String,String> map = new HashMap<String,String>();

                                ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();

                                list.add(map);

                                test.testMethod(list);

                }

}

If you are not able to, no worries. Really you should be happy to know that you have something new to learn. Read through Generics tutorial from Sun. This gives you some insight on the issue and much more. 

Have a look at Java 5 features too. 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: