Page 1 of 1
About Question enthuware.ocpjp.v8.2.1912 :
Posted: Sat Aug 04, 2018 8:34 am
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);
Re: About Question enthuware.ocpjp.v8.2.1912 :
Posted: Sat May 30, 2020 5:06 pm
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.
Re: About Question enthuware.ocpjp.v8.2.1912 :
Posted: Sun May 31, 2020 1:11 am
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.