在编译时,比如编译Boolean Class. public class Boolean { public Booelan(boolean b) { ..... } }在应用时,一般不再是这个Boolean.java文件, { ...... Boolean B = new Boolean(true); ...... }Boolean is a wrapping Class of primitive type boolean. We have to use an Object Class to wrap a primitive type because we're talking Object Oriented Programming. Also, think the Vector Class, or Stack, or ArrayList, or HashMap, they all take Objects only, not primitive types. If vec is a Vector: Vector vec = new Vector(); and b is a boolean type variable: boolean b = true; It's wrong to do this: vec.add(b); One has to wrap it as this: vec.add(new Boolean(b));If you still can not understand, consider to change your career.
public static void main(String[] args){
Boolean boo = new Boolean("True");
if(boo.booleanValue())
System.out.println("boo is "+boo);
}
}
//...
boolean b = true;
Boolean bln = new Boolean(b); //这样原始类型b就被包装到了对象bln之中
if(bln.booleanValue()){ //将对象的值输出
System.out.println("看到这个,马上给我分吧");
}
//...
public class Boolean
{
public Booelan(boolean b)
{
.....
}
}在应用时,一般不再是这个Boolean.java文件,
{
......
Boolean B = new Boolean(true);
......
}Boolean is a wrapping Class of primitive type boolean. We have to use an Object Class to wrap a primitive type because we're talking Object Oriented Programming.
Also, think the Vector Class, or Stack, or ArrayList, or HashMap,
they all take Objects only, not primitive types.
If vec is a Vector: Vector vec = new Vector();
and b is a boolean type variable: boolean b = true;
It's wrong to do this: vec.add(b);
One has to wrap it as this: vec.add(new Boolean(b));If you still can not understand, consider to change your career.