"์๋ , ์๋ฏธ๊ณ !"
"์๋ , ๊น."
"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; //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์ด ๋ฐ์ํ๋ค๋ ์ ์ ์์ง ๋ง์ธ์."
"์, ์ด๋ฏธ ์๊ณ ์์ต๋๋ค. ํญ์ ๋จธ๋ฆฌ ์์ ๋ชจ๋ ๊ฒ์ ์ ์งํ์ง๋ ์์ต๋๋ค."
GO TO FULL VERSION