String s="hoho"
s.subString(0,2).subString(0,1)
객체에 . 을 찍어서 계속 계속 메소드를 호출 하는 것을 본적이 있습니다.
이것이 바로 자기 부르기!!
return this; 라는 생소한 문법을 볼 수 있습니다.
public class test {
public static void main(String args[]){
self s=new self();
s.addOne().addOne().addOne().addOne().print();
}
}
class self{
int num=0;
self addOne(){
num+=1;
return this;
}
void print(){
System.out.println(num);
}
}