"안녕, 아미고!"

"안녕, 김."

"Boolean 유형에 대해 설명하겠습니다. Boolean 유형의 래퍼이며 파이만큼 쉽습니다. 다음은 Boolean 클래스의 단순화된 코드입니다."

암호
class Boolean
{
 public static final Boolean TRUE = new Boolean(true);
 public static final Boolean FALSE = new Boolean(false);

 private final boolean value;

 public Boolean(boolean value)
 {
  this.value = value;
 }

 public boolean booleanValue()
 {
  return value;
 }

 public static Boolean valueOf(boolean b)
 {
  return (b ? TRUE : FALSE);
 }
}

"즉, 클래스는 단순히 부울 유형의 래퍼입니다."

"예. 그리고 두 개의 상수(TRUE 및 FALSE)가 있으며, 기본 값 true 및 false에 해당합니다."

"또한 챔피언처럼 오토박싱을 처리합니다."

암호 실제로 일어나는 일
Boolean a = true;
Boolean b = true;
Boolean c = false;
boolean d = a;
Boolean a = Boolean.valueOf(true);
Boolean b = Boolean.valueOf(true);
Boolean c = Boolean.valueOf(false);
boolean d = a.booleanValue();

"그리고 부울 유형과 부울 유형 간의 비교가 작동하는 방식은 다음과 같습니다."

boolean a = true;
Boolean b = true; //Will be equal to Boolean.TRUE
Boolean c = true; //Will be equal to Boolean.TRUE

a == b; //true (comparison based on primitive value)
a == c; //true (comparison based on primitive value)
b == c; //true (comparison based on references, but they point to the same object)

"독립적인 부울 개체를 만들어야 하는 경우 명시적으로 만들어야 합니다.

boolean a = true;
Boolean b = new Boolean(true); //A new Boolean object
Boolean c = true; //Will be equal to Boolean.TRUE

a == b; //true (comparison based on primitive value)
a == c; //true (comparison based on primitive value)
b == c; //false (comparison based on references; they point to different objects)

"지금은 그게 다인 것 같아요."

"네, 당신의 수업은 Bilaabo보다 짧습니다."

"그래서 if 조건 내에서 부울을 사용할 수 있습니까?"

Boolean less = (2 < 3);
if (less)
{
….
}

"예, less가 null이면 NullPointerException이 발생한다는 점을 잊지 마세요."

"예, 이미 알고 있습니다. 항상 머리 속에 모든 것을 유지하지는 않습니다."