Consumer<T>函数式编程总结
public class Parent { public void getName(String name){ System.out.println("name:" + name); } }
public class Son extends Parent{ @Override public void getName(String name) { System.out.println("hello -->" + name); } }
public class Handler { public void handle(Consumer<String> consumer, String name){ consumer.accept(name); } }
public class Test { public static void main(String[] args) { Parent parent = new Son(); Consumer<String> consumer = parent::getName; Handler handler = new Handler(); handler.handle(consumer, "guodong"); } }
总结:提供一个T类型的输入参数,不返回执行结果,也是可以用来接耦。
郭慕荣博客园