jdk 버전 확장으로 인한 오류들

JINSEON YE·2023년 6월 17일

Diamond operator

  • jdk 7 이후 다이아몬드 연산자 사용으로 컴파일러가 알아서 추론한다.
    제네릭에 타입을 명시하지 않아도 된다.

경고 메세지 : Explicit type argument Memo can be replaced with <>

해결 :
참고

Diamond operator

List.sort()

  • Java 8 이후부터는 List에서는 sort() 메소드를 호출하여 정렬할 수 있.

경고 메세지 : Collections.sort could be replaced with List.sort

상황 : 아래에서 List.sort로 대체하라고 함. List.sort라고 그대로 작성했는데 안 됨.


public void getMemoList() {
		Collections.sort(memoList, new MemoDateComparator().reversed());
}

해결 : Collections 대신 리스트 이름을 적는 것


public void getMemoList() {
		memoList.sort(new MemoDateComparator().reversed());
}

참고

profile
백엔드 개발자

0개의 댓글