About Question enthuware.ocpjp.v8.2.1912 :

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

Moderator: admin

Post Reply
ArpRokz
Posts: 15
Joined: Sun Jan 28, 2018 12:38 pm
Contact:

About Question enthuware.ocpjp.v8.2.1912 :

Post by ArpRokz »

Just an interesting thing I found and though I should share...

Even this works...

IntFunction<IntUnaryOperator> fo = a->b->a-b;

int x = (fo.apply(20)).applyAsInt(5);

System.out.println(15);

saurabh.agarwal560
Posts: 11
Joined: Thu May 28, 2020 9:53 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1912 :

Post by saurabh.agarwal560 »

I tried compiling it and found 15 as a result but I have a doubt that why it fo.apply(20) doesnt throw compilation error as fo is of type Intfunction and the function call should be fo.applyAsInt(20). Please explain.

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

Re: About Question enthuware.ocpjp.v8.2.1912 :

Post by admin »

fo points to in IntFunction object, which has an apply() method not applyAsInt(). So, why do expect fo.applyAsInt() to work?
The internal implementation of this IntFunction returns an IntUnaryOperator. That is what the first post in this thread shows.
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 32 guests