这段代码给出了错误,不知道为什么?错误是"构造函数布尔类Boolean中的布尔值不能应用于给定类型"。我在jdk 7上运行此代码
class Boolean12
{
public static void main(String s[])
{
// this code is to assign boolean values in different form
Boolean c = new Boolean(null);
Boolean d = new Boolean("null");
Boolean e = new Boolean("TRue");
Boolean f = new Boolean(TRue);
Boolean g = new Boolean(true);
System.out.println(c);
System.out.println(d);
System.out.println(e);
System.out.println(f);
System.out.println(g);
}
}
答案 0 :(得分:1)
在您的班级Boolean
中,没有任何匹配的构造函数用于
Boolean c = new Boolean(null);
Boolean d = new Boolean("null");
Boolean e = new Boolean("TRue");
Boolean f = new Boolean(TRue);
Boolean g = new Boolean(true);
然后您无法进行此类初始化。尝试学习Java
。 Boolean
中有一个类名Java
,为什么要创建另一个?
答案 1 :(得分:0)
class Boolean
{
public Boolean(Object object) {
}
public Boolean() {
}
public static void main(String s[])
{
Boolean c = new Boolean(null);
Boolean d = new Boolean("null");
Boolean e = new Boolean("TRue");
Boolean f = new Boolean("TRue");
Boolean g = new Boolean(true);
Boolean h = new Boolean();
System.out.println(c);
System.out.println(d);
System.out.println(e);
System.out.println(f);
System.out.println(g);
System.out.println(h);
}
}
试试这个