ERROR :: constant expression required

ERROR 2020.05.06 댓글 moonsu
728x90

"constant expression required"는 말 그대로 상수 표현이 필수적이라는 뜻으로

상수값이 들어가야 할 부분에 다른 값이 있어 발생하는 오류이다.

 

대표적인 예로 switch ~ case문이 있다.

case에는 반드시 상수값이 들어가야 하며 변수에 final을 선언해 값이 바뀌지 않도록 해야한다.

public static final int CASE_VALUE = 1; //final을 선언해 상수로

switch (num) {
    case CASE_VALUE: //CASE_VALUE 값은 상수!!
    	//_Action_
    break;
    
    default:
    break;
}
728x90
반응형

'ERROR' 카테고리의 다른 글

SDK location not found  (0) 2020.11.09
ERROR :: The requested operation caused a stack overflow  (0) 2020.10.30

댓글