简体   繁体   English

如何创建接口“X”扩展列表接口并使用抽象 class Y 和 ArrayList 实现 X

[英]How to create a interface “X” extending List interface and implement X using a abstract class Y with ArrayList

Currently am stuck in a peculiar state.目前我陷入了一个特殊的 state 中。 I would like to create an interface X which extends java.util.List interface.我想创建一个扩展 java.util.List 接口的接口 X。

Meantime, I am creating an Abstract class Y which implements "X" partially.同时,我正在创建一个抽象 class Y 部分实现“X”。 However, I don't wish to implement methods of List.但是,我不想实现 List 的方法。 Is possible to wire them together using ArrayList?是否可以使用 ArrayList 将它们连接在一起?

public interface X extends Serializable, Cloneable, List<MessageObject>, RandomAccess {

}


public abstract class Y implements X {
}

Regarding the above code, Y needs to implement all methods of ArrayList.关于上面的代码,Y需要实现ArrayList的所有方法。 Is it possible to workaround this?有可能解决这个问题吗? Even creating one more layer inbetween the class should be fine.即使在 class 之间再创建一层也应该没问题。

The requirement is "Y" should have all methods and functionality of ArrayList.要求是“Y”应具有 ArrayList 的所有方法和功能。

You should be able to inherit them from ArrayList.您应该能够从 ArrayList 继承它们。

public abstract class Y extends ArrayList<MessageObject> implements X {
}

I have solved the problem with the following solution:我已经通过以下解决方案解决了这个问题:

/**
 * A runtime representation of a section.
 *
 * The message section encapsulates an array of {@link MessageObject}.
 *
 * @see MessageObject
 */
public interface X extends List, Serializable, Cloneable, RandomAccess {
//Code
}

The same in implemeneted by an AbstractClass由 AbstractClass 实现的相同

public abstract class Y extends ArrayList implements MessageSection {

//Code

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM