๋ถ€์šธ

์ž๋ฐ” ๋ฉ€ํ‹ฐ์Šค๋ ˆ๋”ฉ
๋ ˆ๋ฒจ 9 , ๋ ˆ์Šจ 6
์‚ฌ์šฉ ๊ฐ€๋Šฅ

"์•ˆ๋…•, ์•„๋ฏธ๊ณ !"

"์•ˆ๋…•, ๊น€."

"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์ด ๋ฐœ์ƒํ•œ๋‹ค๋Š” ์ ์„ ์žŠ์ง€ ๋งˆ์„ธ์š”."

"์˜ˆ, ์ด๋ฏธ ์•Œ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ํ•ญ์ƒ ๋จธ๋ฆฌ ์†์— ๋ชจ๋“  ๊ฒƒ์„ ์œ ์ง€ํ•˜์ง€๋Š” ์•Š์Šต๋‹ˆ๋‹ค."

์ฝ”๋ฉ˜ํŠธ
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION