使用通用接口的方法
use method from generic interface
我有这样的界面:
public interface Segments <T> {
List<T> getSegments();
}
和一个class:
public class Tree<S, T extends Segmentable<S>>{
}
我想从接口实现和使用 getSegments() 方法,但不知道如何实现。
您要么需要在class中实现接口如下:
public class Tree<S, T extends Segmentable<S>> implements Segments<S> {
@Override
public List<S> getSegments() {
// Return some List<S> that you want here.
}
}
或者您需要在已经实现它的对象上调用 getSegments()
方法。
我有这样的界面:
public interface Segments <T> {
List<T> getSegments();
}
和一个class:
public class Tree<S, T extends Segmentable<S>>{
}
我想从接口实现和使用 getSegments() 方法,但不知道如何实现。
您要么需要在class中实现接口如下:
public class Tree<S, T extends Segmentable<S>> implements Segments<S> {
@Override
public List<S> getSegments() {
// Return some List<S> that you want here.
}
}
或者您需要在已经实现它的对象上调用 getSegments()
方法。