泛型接口实现方式 子类继续用泛型 1interface IMessage<T>{2 public String echo(T t);3}4class MessageImpl<S> implements IMessage <S>{5 public String echo(S t){6 return "[echo]" + t;7 }8}9public class Type{10 public static void main(String args []){11 12 IMessage<String> msg = new MessageImpl<String>();13 System.out.println(msg.echo("我是菜菜"));14 15 }1 collapsed line16} 子类直接指定泛型 1interface IMessage<T>{2 public String echo(T t);3}4class MessageImpl implements IMessage <String>{5 public String echo(String t){6 return "[echo]" + t;7 }8}9public class Type{10 public static void main(String args []){11 12 IMessage<String> msg = new MessageImpl();13 System.out.println(msg.echo("我是菜菜"));14 15 }1 collapsed line16}