c******n 发帖数: 4965 | 1 如果base 是个generics type, extend base class 的时候,不加parameter type
居然也能成功,但是这出来是什么东西呢?
比如下面的class g, 它的ll member 到底是什么type 呢?
import java.util.*;
class f{
public List ll= new ArrayList();
}
class g extends f {
}
class h {
//public static void fun(List extends f super f>> dd ){
public static void fun(List extends f> dd ){
}
}
public class a {
public static void main(String [] args ) {
//List l = new ArrayList();
//h.fun(l);
g gg = new g( | m******t 发帖数: 2416 | 2
It would be a raw List.
Your code causes warnings like this in my Eclipse:
"f is a raw type. References to generic type f
should be parameterized."
Nice try. I can almost hear 3k laughing at you. ;-)
【在 c******n 的大作中提到】 : 如果base 是个generics type, extend base class 的时候,不加parameter type : 居然也能成功,但是这出来是什么东西呢? : 比如下面的class g, 它的ll member 到底是什么type 呢? : : import java.util.*; : class f{ : public List ll= new ArrayList(); : } : class g extends f { : }
| F****n 发帖数: 3271 | 3 There are only Generics types but no Generics "objects" in Java. This means
Generics type / parameters are only meaningful in class definition (thus in
Class objects), and do not have any impact on runtime objects. The generics
types are only used at compiling time to help find errors.
【在 c******n 的大作中提到】 : 如果base 是个generics type, extend base class 的时候,不加parameter type : 居然也能成功,但是这出来是什么东西呢? : 比如下面的class g, 它的ll member 到底是什么type 呢? : : import java.util.*; : class f{ : public List ll= new ArrayList(); : } : class g extends f { : }
|
|