
A method can be declared [[final]] to prevent subclasses from overriding or hiding it. It is a compile-time error to attempt to override or hide a final method. A private method and all methods declared immediately within a final class(§8.1.1.2) behave as if they are final, since it is impossible to override them.
서브클래스가 오버라이딩이나 숨기는 것을 방지하기 위해 메서드는 final로 선언할 수 있다. 오버라이드를 시도하거나 final method를 숨기면 컴파일에러가 발생한다. private 메서드와 final class안에 바로 선언된 모든 메서드는 오버라이드하기 불가능하기 때문에 final인 것처럼 행동한다.
At run time, a machine-code generator or optimizer can "inline" the body of a
finalmethod, replacing an invocation of the method with the code in its body. The inlining process must preserve the semantics of the method invocation. In particular, if the target of an instance method invocation is [[null]], then a [[NullPointerException]] must be thrown even if the method is inlined. A Java compiler must ensure that the exception will be thrown at the correct point, so that the actual arguments to the method will be seen to have been evaluated in the correct order prior to the method invocation.
런타임에서 머신 코드 생성기 또는 옵티마이저는 final method의 body를 "inline"할 수 있으며, 메서드의 호출을 body에 있는 코드로 대체할 수 있다. 인라인 프로세스는 메서드 호출의 의미를 보존해야 한다. 특히, 인스턴스 메서드 호출의 대상이 null이라면, 메서드가 inline되더라도 NullPointerException은 throw 되어야 한다. 자바 컴파일러는 메서드 호출전에 실제 인수가 올바른 순서로 평가된 것을 보일 수 있도록 예외가 올바른 지점에서 던져지게끔 보장해야 한다.