开发者

What is mean by Collection<? extends EmpApp>?

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?


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


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).


A collection is group of object to be treated as a single unit.Arbitrary objects can be stored,retrieved,& manipulated as elements of collection.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜