상세 컨텐츠

본문 제목

[java] JAVA 1.7의 Integer.compare를 1.6에서 실행할때

헉!!/jsp, java

by 권태성 2013. 12. 10. 13:46

본문

JAVA 1.7에서 작성한 소스를 1.6에서 빌드를 하려고 하면 일부 메소드들이 지원되지 않아 오류가 납니다.

아래 예제는 그 중 Integer.compare 메소드의 경우 입니다.

  • compare

    public static int compare(int x,
              int y)
    Compares two int values numerically. The value returned is identical to what would be returned by:
        Integer.valueOf(x).compareTo(Integer.valueOf(y))
     
    Parameters:
    x - the first int to compare
    y - the second int to compare
    Returns:
    the value 0 if x == y; a value less than 0 if x < y; and a value greater than 0 if x > y
    Since:
    1.7

위 문서는 JAVA API 1.7에 있는 compare 메소드에 관한 내용 입니다. 보시다시피 1.7에 추가된것을 확인하실 수 있습니다.

(API 출처 : http://docs.oracle.com/javase/7/docs/api/index.html)


간단하게 1.7 이하 버전에서 사용시에는 위 내용에 있듯이 Integer.valueOf(x).compareTo(Integer.valueOf(y)) 형태로 사용하시면 됩니다.





관련글 더보기