tevelop RSS 태그 관리 글쓰기 방명록
2023-01-10 20:59:25

https://stackoverflow.com/questions/4162531/making-java-method-arguments-as-final

public String changeTimezone( Timestamp stamp, Timezone fTz, Timezone toTz){
    return ....
}

public String changeTimezone(final Timestamp stamp, final Timezone fTz,
        final Timezone toTz){
    return ....
}

parameter를 final로 설정하는 것과 안 하는 것의 차이

  • As a formal method parameter is a local variable, you can access them from inner anonymous classes only if they are declared as final
  • final is used here to ensure the two indexes i and j won't accidentally be reset by the method. 메서드에 의해 실수로 재설정 되지 않도록 하기 위해 사용한다.
  • It's a handy way to protect against an insidious bug that erroneously changes the value of your parameters. 매개변수 값을 잘못 변경하는 버그로부터 보호하는 편리한 방법이다.
  • The final prevents you from assigning a new value to the variable, and this can be helpful in catching typos. final은 변수에 새 값을 할당하는 것을 방지하며 오타를 잡는데 도움이 된다.

'내일배움캠프 > TIL' 카테고리의 다른 글

2022/1/12  (0) 2023.01.12
2023/1/11  (1) 2023.01.11
2023/1/9  (0) 2023.01.09
2023/1/7  (0) 2023.01.07
2023/1/5  (0) 2023.01.05
tevelop. Designed by 코딩재개발.