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);
About Question enthuware.ocpjp.v8.2.1912 :
Moderator: admin
-
- Posts: 15
- Joined: Sun Jan 28, 2018 12:38 pm
- Contact:
-
- Posts: 11
- Joined: Thu May 28, 2020 9:53 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1912 :
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.
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1912 :
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.
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.
Who is online
Users browsing this forum: No registered users and 100 guests