Last active
December 27, 2021 13:16
-
-
Save haxianhe/d37fa2710f8ff29e0a0749faa12b99c9 to your computer and use it in GitHub Desktop.
Lambad case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.haxianhe; | |
import static com.haxianhe.ClassA.test; | |
import java.util.function.Predicate; | |
/** | |
* @author haxianhe <[email protected]> | |
* Created on 2021-12-27 | |
*/ | |
public class LambdaTest { | |
public static void main(String[] args) { | |
boolean bool = (new ClassB()).set(test(i -> i == null || "".equals(i)), "").test(); | |
System.out.println("result: "+bool); | |
} | |
} | |
@FunctionalInterface | |
interface ClassA<T> { | |
static <T> ClassA<T> test(Predicate<T> predicate) { | |
return predicate::test; | |
} | |
boolean isEmpty(T param); | |
} | |
class ClassB<T> { | |
private ClassA classA; | |
private T param; | |
ClassB<T> ClassB(ClassA classA, T param) { | |
this.classA = classA; | |
this.param = param; | |
return this; | |
} | |
ClassB<T> set(ClassA classA, T param) { | |
this.classA = classA; | |
this.param = param; | |
return this; | |
} | |
public boolean test() { | |
return classA.isEmpty(param); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment