import java.util.function.Consumer; public class Main { public static void main(String[] args) { Message message = new Message("w3cschool.cn"); Consumer<Message> messageConsumer = (t) -> System.out.println(t); Consumer<Message> endConsumer = (t) -> System.out.println("End: " + t); messageConsumer.andThen(endConsumer).accept((message)); } } class Message { private String msg; public Message(String msg) { this.msg = msg; } public String getMessage() { return msg; } public String toString() { return getMessage(); } }