2015-12-02 09:20:27 -08:00
|
|
|
// functional/MultiUnbound.java
|
2016-12-30 17:23:13 -08:00
|
|
|
// (c)2017 MindView LLC: see Copyright.txt
|
2015-12-02 09:20:27 -08:00
|
|
|
// We make no guarantees that this code is fit for any purpose.
|
2016-09-23 13:23:35 -06:00
|
|
|
// Visit http://OnJava8.com for more book information.
|
2015-12-02 09:20:27 -08:00
|
|
|
// Unbound methods with multiple arguments
|
|
|
|
|
|
|
|
class This {
|
|
|
|
void two(int i, double d) {}
|
|
|
|
void three(int i, double d, String s) {}
|
|
|
|
void four(int i, double d, String s, char c) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
interface TwoArgs {
|
2016-11-21 12:37:57 -08:00
|
|
|
void call2(This athis, int i, double d);
|
2015-12-02 09:20:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
interface ThreeArgs {
|
2016-11-21 12:37:57 -08:00
|
|
|
void call3(This athis, int i, double d, String s);
|
2015-12-02 09:20:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
interface FourArgs {
|
|
|
|
void call4(
|
2016-11-21 12:37:57 -08:00
|
|
|
This athis, int i, double d, String s, char c);
|
2015-12-02 09:20:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public class MultiUnbound {
|
|
|
|
public static void main(String[] args) {
|
|
|
|
TwoArgs twoargs = This::two;
|
|
|
|
ThreeArgs threeargs = This::three;
|
|
|
|
FourArgs fourargs = This::four;
|
2016-11-21 12:37:57 -08:00
|
|
|
This athis = new This();
|
|
|
|
twoargs.call2(athis, 11, 3.14);
|
|
|
|
threeargs.call3(athis, 11, 3.14, "Three");
|
|
|
|
fourargs.call4(athis, 11, 3.14, "Four", 'Z');
|
2015-12-02 09:20:27 -08:00
|
|
|
}
|
|
|
|
}
|