About Question enthuware.ocpjp.i.v11.2.3093 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
javabean68
Posts: 31
Joined: Wed Mar 16, 2016 8:38 am
Contact:

About Question enthuware.ocpjp.i.v11.2.3093 :

Post by javabean68 »

Hi all,

would have option 4 been correct

Code: Select all

public ArrayList<? extends Integer> transform(Set<Integer> list)
if we had:

Code: Select all

ArrayList<? extends Number>...

as return type in Base?

Thanks in advance,
Bye :?
Fabio

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3093 :

Post by admin »

What happened when you tried it out?
If you like our products and services, please help us by posting your review here.

Val Martinez
Posts: 11
Joined: Thu Sep 01, 2022 10:58 am
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3093 :

Post by Val Martinez »

I dont really catch why "ArrayList<? extends Integer> is not a subtype of ArrayList<Number>"

any type that extends from Integer, would be also a subtype of Number, because of its hierarchy relation. isn't it?

thanks in advance.

Val Martinez
Posts: 11
Joined: Thu Sep 01, 2022 10:58 am
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3093 :

Post by Val Martinez »

Val Martinez wrote:
Sat Jan 14, 2023 4:50 am
I dont really catch why "ArrayList<? extends Integer> is not a subtype of ArrayList<Number>"

any type that extends from Integer, would be also a subtype of Number, because of its hierarchy relation. isn't it?

thanks in advance.
Im sorry, I'll asnwer myself.

Already have studied it in the official docs, but its a bit counterintuitive. Integer, extends Number, but an Array of Integers doesnt extends an Array of Numbers, because simply, these types Array<Integer> and Array<Number> are not related on the Java hierarchy

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3093 :

Post by admin »

List<Number> means, it is a list of Numbers. Every element in this list will be always a Number. For example, an element in this list could be an Integer or a Short or some other type of Number. We know for sure that whatever element is present in this list will be a Number. So, you can add an Integer or Short to it.

List<? extends Number> is a list of some class that extends Number but we don't know which type. For example, this list could be a list of Integers, in which case, it cannot contain a Short or some other type of Number. This list could also be a list of Shorts, in which case, it cannot contain Integers.
The same logic applies to List<? extends Integer>.

You can see that both types of list have different conditions on what they may contain. Therefore, List<? extends Number> or List<? extends Integer> is not a subtype of List<Number>.
If you like our products and services, please help us by posting your review here.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3093 :

Post by admin »

You might want to check out this post: https://enthuware.com/forum/viewtopic.php?f=2&t=473
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 69 guests