Skip to content

Instantly share code, notes, and snippets.

@haxianhe
Last active December 27, 2021 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haxianhe/d37fa2710f8ff29e0a0749faa12b99c9 to your computer and use it in GitHub Desktop.
Save haxianhe/d37fa2710f8ff29e0a0749faa12b99c9 to your computer and use it in GitHub Desktop.
Lambad case
package com.haxianhe;
import static com.haxianhe.ClassA.test;
import java.util.function.Predicate;
/**
* @author haxianhe <haxianhe@gmail.com>
* 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