Hi I think, that this question has wrong answer.
the first one is marked as correct anwer, but it doesn't compile
public static double compute(double base, Function<Integer, Integer > func){
return func.apply((int)base);
}
However the third one does compile and is marked as invalid.
About Question enthuware.ocpjp.v8.2.1878 :
Moderator: admin
-
- Posts: 1
- Joined: Sun Oct 11, 2015 3:07 pm
- Contact:
About Question enthuware.ocpjp.v8.2.1878 :
- Attachments
-
- Screen Shot 2018-01-01 at 11.46.42.png (177.97 KiB) Viewed 5169 times
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1878 :
Are you sure you typed the code as given in the question while trying it out? I tried it just now and option 1 compiles fine.
-Paul.
-Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 31
- Joined: Sun Oct 13, 2013 1:20 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1878 :
I already knew that widening and boxing do not go together. But did I just learn today that widening and UNboxing is allowed? This part is not testing Java 8, but okay, nice to know.
-
- Posts: 33
- Joined: Sat Feb 15, 2020 12:44 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1878 :
I wonder if the cast from double to int might pose a problem since the max value of a double is 1.7*10^308 and that of an int is just 2^31-1, and also regarding their minimums.
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1878 :
Should be easy to check
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 59 guests