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类型的输入参数,不返回执行结果,也是可以用来接耦。
标签:String,void,编程,name,class,Consumer,public,函数 From: https://www.cnblogs.com/jelly12345/p/17062882.html