Final arguments in interface methods - what's the point?

前端 未结 5 1894
甜味超标
甜味超标 2020-11-28 03:26

In Java, it is perfectly legal to define final arguments in interface methods and do not obey that in the implementing class, e.g.:

public inter         


        
5条回答
  •  清酒与你
    2020-11-28 03:43

    It doesn't seem like there's any point to it. According to the Java Language Specification 4.12.4:

    Declaring a variable final can serve as useful documentation that its value will not change and can help avoid programming errors.

    However, a final modifier on a method parameter is not mentioned in the rules for matching signatures of overridden methods, and it has no effect on the caller, only within the body of an implementation. Also, as noted by Robin in a comment, the final modifier on a method parameter has no effect on the generated byte code. (This is not true for other uses of final.)

提交回复
热议问题