-1

I must admit that Java is a little messy when working with templates...

As the title explains, i'm trying to use an static member coded on the super class of some generalizated attribute. How can i do this?

For example:

class A {
    public static void someAction();
}

class B<T extends A>{ (...) }

¿how do i access the A's someAction() method in the class B?

4

1 回答 1

5

我如何someAction()从 B 类访问 A 的方法?

打电话

A.someAction()

这是一个静态方法,所以 B 的类型参数扩展 A 的事实没有任何影响。


如果someAction应该是通用的并且您想将 B 的<T>参数与 A 一起使用,则someAction使用其自己的类型参数声明:

public static <T> void someAction(.../* use T here maybe */) { ... }

然后B你可以做

A.<T>someAction(...)

使<T>before与 body 中的可见someAction相同。<T extends A>B

于 2013-05-25T21:59:40.363 回答