FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
OnJava8-Examples/generics/ApplyTest.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
/
generics
/
ApplyTest.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
65 lines (61 loc) · 1.59 KB
Breadcrumbs
OnJava8-Examples
/
generics
/
ApplyTest.java
Copy path
File metadata and controls
65 lines (61 loc) · 1.59 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
// generics/ApplyTest.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
.*;
import
java
.
util
.
function
.*;
import
onjava
.*;
public
class
ApplyTest
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
List
<
Shape
>
shapes
=
Suppliers
.
create
(
ArrayList
::
new
,
Shape
::
new
,
3
);
Apply
.
apply
(
shapes
,
Shape
.
class
.
getMethod
(
"rotate"
));
Apply
.
apply
(
shapes
,
Shape
.
class
.
getMethod
(
"resize"
,
int
.
class
),
7
);
List
<
Square
>
squares
=
Suppliers
.
create
(
ArrayList
::
new
,
Square
::
new
,
3
);
Apply
.
apply
(
squares
,
Shape
.
class
.
getMethod
(
"rotate"
));
Apply
.
apply
(
squares
,
Shape
.
class
.
getMethod
(
"resize"
,
int
.
class
),
7
);
Apply
.
apply
(
new
FilledList
<>(
Shape
::
new
,
3
),
Shape
.
class
.
getMethod
(
"rotate"
));
Apply
.
apply
(
new
FilledList
<>(
Square
::
new
,
3
),
Shape
.
class
.
getMethod
(
"rotate"
));
SimpleQueue
<
Shape
>
shapeQ
=
Suppliers
.
fill
(
new
SimpleQueue
<>(),
SimpleQueue
::
add
,
Shape
::
new
,
3
);
Suppliers
.
fill
(
shapeQ
,
SimpleQueue
::
add
,
Square
::
new
,
3
);
Apply
.
apply
(
shapeQ
,
Shape
.
class
.
getMethod
(
"rotate"
));
}
}
/* Output:
Shape 0 rotate
Shape 1 rotate
Shape 2 rotate
Shape 0 resize 7
Shape 1 resize 7
Shape 2 resize 7
Square 3 rotate
Square 4 rotate
Square 5 rotate
Square 3 resize 7
Square 4 resize 7
Square 5 resize 7
Shape 6 rotate
Shape 7 rotate
Shape 8 rotate
Square 9 rotate
Square 10 rotate
Square 11 rotate
Shape 12 rotate
Shape 13 rotate
Shape 14 rotate
Square 15 rotate
Square 16 rotate
Square 17 rotate
*/
Back
|
FazBrowse Home
|
New Git URL