OnJava8-Examples/innerclasses/arr/ArgReturnReferences.java

36 lines
894 B
Java
Raw Normal View History

2015-09-07 11:44:36 -06:00
// innerclasses/arr/ArgReturnReferences.java
2015-06-15 17:47:35 -07:00
// <20>2015 MindView LLC: see Copyright.txt
// Demonstrates method references
package innerclasses.arr;
import java.util.function.*;
import static com.mindviewinc.util.Print.*;
class Y {
static Y create() { return new Y(); }
static void absorb(Y y) {}
static String transform1(Y y) { return "Y"; }
static String transform2(Y y, String s) {
return "Y" + " " + s;
}
}
public class ArgReturnReferences {
Supplier<Y> supply = Y::create;
Consumer<Y> consume = Y::absorb;
Function<Y, String> f1arg = Y::transform1;
BiFunction<Y, String, String> f2arg =
Y::transform2;
public static void main(String[] args) {
ArgReturnReferences arr =
new ArgReturnReferences();
Y y = arr.supply.get();
arr.consume.accept(y);
print(arr.f1arg.apply(y));
print(arr.f2arg.apply(y, "Howdy"));
}
2015-09-07 11:44:36 -06:00
}
/* Output:
2015-06-15 17:47:35 -07:00
Y
Y Howdy
2015-09-07 11:44:36 -06:00
*/