Develop

[Java] illegal modifier for parameter id only final is permitted 본문

웹 개발/Java

[Java] illegal modifier for parameter id only final is permitted

개발 기록 2024. 2. 22. 10:56

 

회원가입시 서버단에서도 유효성 검사를 하기 위해 자바 정규식을 이용했다.

정규식이 바뀔일이 없기 때문에  final 로 선언하였는데 오류가 떴다.

 

오류

illegal modifier for parameter id only final is permitted

 

 

 

처음 작성한 코드

 

// 회원가입
@ResponseBody
@RequestMapping(value = "userJoin", method = RequestMethod.POST)
public int userJoinPOST(UserVO userVO, String us_pw_check) throws Exception {
    logger.debug("userJoinPOST(UserVO userVO)호출");
    logger.debug("회원가입 정보 userVO : " + userVO);

    boolean us_id = false, us_pw = false, us_pw_ck = false, us_name = false, us_nickname = false, us_tel = false;
    public static final String us_id_reg_check = "^[a-zA-Z0-9][a-zA-Z0-9]{3,8}";
    public static final String us_pw_reg_check = "^[a-zA-Z0-9][a-zA-Z0-9]{3,8}";
    public static final String us_name_reg_check = "^[ㄱ-힣][ㄱ-힣]{1,10}";
    public static final String us_nickname_reg_check = "^[a-zA-Z0-9ㄱ-힣][a-zA-Z0-9ㄱ-힣]{1,8}";
    public static final String us_tel_reg_check = "^[0-9][0-9]{8}";

    us_id = Pattern.matches(us_id_reg_check, userVO.getUs_id());
    us_pw = Pattern.matches(us_pw_reg_check, userVO.getUs_id());
    us_name = Pattern.matches(us_name_reg_check, userVO.getUs_id());
    us_nickname = Pattern.matches(us_nickname_reg_check, userVO.getUs_id());
    us_tel = Pattern.matches(us_tel_reg_check, userVO.getUs_id());

    if (userVO.getUs_pw().equals(us_pw_check)) {
        us_pw_ck = true;
    }

    // 모든 조건 만족시
    if (us_id && us_pw && us_pw_ck && us_name && us_nickname && us_tel) {
        return uService.userJoin(userVO);
    }
    return 0;
}

 

 

고친 코드

 

	public static final String us_id_reg_check = "^[a-zA-Z0-9][a-zA-Z0-9]{3,8}";
	public static final String us_pw_reg_check = "^[a-zA-Z0-9][a-zA-Z0-9]{3,8}";
	public static final String us_name_reg_check = "^[ㄱ-힣][ㄱ-힣]{1,10}";
	public static final String us_nickname_reg_check = "^[a-zA-Z0-9ㄱ-힣][a-zA-Z0-9ㄱ-힣]{1,8}";
	public static final String us_tel_reg_check = "^[0-9][0-9]{8}";
	
	// 회원가입
	@ResponseBody
	@RequestMapping(value = "userJoin", method = RequestMethod.POST)
	public int userJoinPOST(UserVO userVO, String us_pw_check) throws Exception {
		logger.debug("userJoinPOST(UserVO userVO)호출");
		logger.debug("회원가입 정보 userVO : " + userVO);
		
		boolean us_id = false, us_pw = false, us_pw_ck = false, us_name = false, us_nickname = false, us_tel = false;
		
		
		us_id = Pattern.matches(us_id_reg_check, userVO.getUs_id());
		us_pw = Pattern.matches(us_pw_reg_check, userVO.getUs_id());
		us_name = Pattern.matches(us_name_reg_check, userVO.getUs_id());
		us_nickname = Pattern.matches(us_nickname_reg_check, userVO.getUs_id());
		us_tel = Pattern.matches(us_tel_reg_check, userVO.getUs_id());

		if (userVO.getUs_pw().equals(us_pw_check)) {
			us_pw_ck = true;
		}

		// 모든 조건 만족시
		if (us_id && us_pw && us_pw_ck && us_name && us_nickname && us_tel) {
			return uService.userJoin(userVO);
		}
		return 0;
	}

 

 

원인

지역변수 위치에 작성해놓고 public static을 적어놓아서 난 오류였다.

따라서 지역변수로 사용할거면 public static을 지우고 final 만 사용하던가

아니면 전역변수로 빼내야한다.

나는 나중에 또 쓸일이 있을거라 생각하여 전역변수로 수정했다.


 

참고한 글

 

자바 관련해서 초보적인 질문입니다. | KLDP

 

자바 관련해서 초보적인 질문입니다. | KLDP

이 중에서 showArea 메소드의 변수들을 private으로 놓으면 illegal modifier for parameter이라면서 only final is permitted라고 합니다. 왜 문제가 되는 것이지요? 다른 클래스에서 showArea 메소드를 활용하기 때문

kldp.org