Programming

[Android] 클래스 생성 시, 변수 개수에 따라 센스있게 처리해주기

 2016. 8. 23. 19:36
반응형
// parameter 2개만 있을 떄 처리해줌
public Note(@Nullable String title, @Nullable String description){
this(title, description, null);
}

public Note(@Nullable String title, @Nullable String description, @Nullable String imageUrl){
mId = UUID.randomUUID().toString();
mTitle = title;
mDescription = description;
mImageUrl = imageUrl;
}


변수가 2개만 있을 때 위의 메소드가 받아주고, 

맨마지막 변수에 null 값을 넣어서 변수 3개까리 메소드가 처리해준다

감동적ㅋㅋ

반응형