producer extends vs consumer super​ for generics

gudii9
gudii9 used Ask the Experts™
on
hi,



I am not clear on producer extends vs consumer super​ for generics



usually in ejb jms mdb world

if some one says consumer means who consumes messages which producer puts in queue right



But here concept seems reverse

producer extends

can read but cannot add
 consumer super​​
can add but cannot read to list?


please advise
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Engineer
Commented:
PECS (producer extends, consumer super) applies to using generics with collections.

If you have a collection from which you are reading/using elements, then that collection is a producer.
In this case, you want to use: Collection<? extends BaseClass>

If you have a collection into which you are adding new elements, then that collection is a consumer.
In this, you want to use: Collection<? super BaseClass>

Author

Commented:

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial