有没有可能在Java中以某种方式在众所周知的接口(interface)List中添加一个新的自定义方法?我试图将 List 接口(interface)实现为“公共(public)抽象类 MyList”,但是,我想实现它保持与接口(interface)“List”相同的名称。比如后面按如下方式实现:
List mylist = new ArrayList();
mylist.newmethod();
最佳答案
不,Java 不支持这样的功能。使用组合。
关于Java:向接口(interface) List<E> 添加一个新方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27956138/