class Animal { boolean canHop = true; boolean canSwim; int x = 1; int y = 10; } interface CheckIface { int test1(Animal a); } //interface Predicate{ // boolean test(T t); //} class Solution { static final int i = 0; public static void main(String[] args) { Animal animal = new Animal(); print1(animal, a -> { return a.x; }); print1(animal, a -> a.y); print1(animal, a -> { return a.canHop ? 1 : 0; }); print(animal, a -> a.canHop); print(animal, a -> a.canSwim); } static void print1(Animal a, CheckIface check) { if (check.test1(a) > 0) System.out.println("test " + check); } static void print(Animal a, Predicate<Animal> check) { if (check.test(a)) System.out.println("test1 " + check); }
2020-03-09
Lambda, Predicate
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment