前几天我注意到我可以调用 boolean.class,但不能调用 integer.class(或其他原语)。是什么让 boolean 值如此特别?
注意:我说的是 boolean.class,而不是 Boolean.class(这是有道理的)。
Duh:我尝试了 integer.class,而不是 int.class。难道我不觉得自己很蠢吗:\
最佳答案
不是 integer.class
而是 int.class
。是的你可以。 JRE 6:
public class TestTypeDotClass{
public static void main(String[] args) {
System.out.println(boolean.class.getCanonicalName());
System.out.println(int.class.getCanonicalName());
System.out.println(float.class.getCanonicalName());
System.out.println(Boolean.class.getCanonicalName());
}
}
输出
boolean
int
float
java.lang.Boolean
关于java - boolean 值类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1019208/