FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
OnJava8-Examples/functional/FunctionVariants.java at master · CSapprenticeWT/OnJava8-Examples · GitHub
CSapprenticeWT
OnJava8-Examples
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
OnJava8-Examples
/
functional
/
FunctionVariants.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
65 lines (58 loc) · 1.54 KB
Breadcrumbs
OnJava8-Examples
/
functional
/
FunctionVariants.java
Copy path
File metadata and controls
65 lines (58 loc) · 1.54 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// functional/FunctionVariants.java
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import
java
.
util
.
function
.*;
class
Foo
{}
class
Bar
{
Foo
f
;
Bar
(
Foo
f
) {
this
.
f
=
f
; }
}
class
IBaz
{
int
i
;
IBaz
(
int
i
) {
this
.
i
=
i
;
}
}
class
LBaz
{
long
l
;
LBaz
(
long
l
) {
this
.
l
=
l
;
}
}
class
DBaz
{
double
d
;
DBaz
(
double
d
) {
this
.
d
=
d
;
}
}
public
class
FunctionVariants
{
static
Function
<
Foo
,
Bar
>
f1
=
f
->
new
Bar
(
f
);
static
IntFunction
<
IBaz
>
f2
=
i
->
new
IBaz
(
i
);
static
LongFunction
<
LBaz
>
f3
=
l
->
new
LBaz
(
l
);
static
DoubleFunction
<
DBaz
>
f4
=
d
->
new
DBaz
(
d
);
static
ToIntFunction
<
IBaz
>
f5
=
ib
->
ib
.
i
;
static
ToLongFunction
<
LBaz
>
f6
=
lb
->
lb
.
l
;
static
ToDoubleFunction
<
DBaz
>
f7
=
db
->
db
.
d
;
static
IntToLongFunction
f8
=
i
->
i
;
static
IntToDoubleFunction
f9
=
i
->
i
;
static
LongToIntFunction
f10
=
l
-> (
int
)
l
;
static
LongToDoubleFunction
f11
=
l
->
l
;
static
DoubleToIntFunction
f12
=
d
-> (
int
)
d
;
static
DoubleToLongFunction
f13
=
d
-> (
long
)
d
;
public
static
void
main
(
String
[]
args
) {
Bar
b
=
f1
.
apply
(
new
Foo
());
IBaz
ib
=
f2
.
apply
(
11
);
LBaz
lb
=
f3
.
apply
(
11
);
DBaz
db
=
f4
.
apply
(
11
);
int
i
=
f5
.
applyAsInt
(
ib
);
long
l
=
f6
.
applyAsLong
(
lb
);
double
d
=
f7
.
applyAsDouble
(
db
);
l
=
f8
.
applyAsLong
(
12
);
d
=
f9
.
applyAsDouble
(
12
);
i
=
f10
.
applyAsInt
(
12
);
d
=
f11
.
applyAsDouble
(
12
);
i
=
f12
.
applyAsInt
(
13.0
);
l
=
f13
.
applyAsLong
(
13.0
);
}
}
Back
|
FazBrowse Home
|
New Git URL