直接上菜 /*接口类*/ public interface MsgListener{ public void afterMsgRecived(String msgData); } /*工具类*/ public class Tools{ public static void getMsgData(String reciver,MsgListener listener){ reciver+=reciver; //关键的来了 listener.afterMsgRecived(reciver); } } //调用 public static void main(String[] args){ String reciver="JACK THE REAPER"; //调用 Tools.getMsgData(reciver,new MsgListener(){ @override public void afterMsgRecived(String msgData){ System.out.println(msgData); } }); } 最后,yes,yes,你会看到控制台输出:"JACK THE REAPERJACK THE REAPER";
时间: 2024-10-05 12:35:40