
정적 메소드 컨벤션
-
from : 하나의 매개변수로 해당 타입의 인스턴스를 반환
ex) Date.from(instance) -
of : 여러개의 매개변수로 적합한 인스턴스를 반환
ex) EnumSet.of(A,B,C) -
instatnce or getInstance : 매개변수로 명시한 인스턴스를 반환하지만, 같은 인스턴스임을 보장하지 않음
ex) StackWalker.getInstance(options) -
create or newInstance : 매번 새로운 인스턴스를 반환하는 것을 보장
ex) Array.newInstance(callObject, arrayList) -
getType : getInstance와 같으나, 생성한 클래스가 아닌 다른 클래스에 팩터리 메서드를 정의할 때 사용
ex) Files.getFileStore(path) -
newType : newInstatnce와 같으나, 생성할 클래스가 아닌 다른 클랙스에 팩터리 메서드를 정의할 때 사용
ex) Files.newBufferedRader(path) -
type : getType과 newType의 간결한 버전
ex) Collections.list(someList)




近期评论