views:

54

answers:

2

In my code i am using two different class objects empobj & employee. Eclipse asks to change the code

empobj.addAll(employee);

to

empobj.addAll((Collection<? extends EmpApp>) employee);

What does it mean? I cannot understand the concept here. Can I get any clarifications about this?

+1  A: 

addAll takes as its parameter a Collection and then adds all the elements of that collection to itself. In your case, you're trying to give it something that is not a Collection, so the compiler is trying to make it work by casting the argument to the correct type. In this particular case, the correct type is a collection of some object which extends EmpApp, i.e., Collection<? extends EmpApp>.

Judging from the name of your variable, employee probably isn't a collection, so you need to revisit the API for whatever collection empobj is and find out how you can add a single element to it (likely add).

Shakedown
Thanks for your reply. But the question(http://stackoverflow.com/questions/3545183/how-to-add-an-object-into-another-object-set) asked here by me, led me here...By your reply i cant add employee object with addall() into empobj, right. May you tell me how to over come this problem. I want to add employee objects into empobj object.
NooBDevelopeR
If it is jsut a single object you just call empobj.add((EmpApp)employee); rather than addAll()
Andrew
A: 
Collection<? extends EmpApp>

Is a definition of a collection. The "employee into a collection which contains objects of a class which extends EmpApp. The "?" in the generic means that Eclipse isn't sure what classname should be there.

For more on generics in Java, here's the wikipedia article

indyK1ng