Why private method can not be final as well?

前端 未结 3 1213
难免孤独
难免孤独 2020-12-14 06:04

Is it redundant to add private and final to a same method?

class SomeClass {

    //--snip--

    private final void doStuff()
             


        
3条回答
  •  情深已故
    2020-12-14 06:43

    Basically, it's allowed because they didn't feel like it's worthwhile to put a special case prohibiting the private modifier. It's like how you can also declare methods on an interface as public, or nested classes in an interface as static, even though those keywords are implied in interfaces. You can also declare final methods on a final class, etc.

    Java took the stance of not complaining when you add redundant modifiers. They do it consistently.

提交回复
热议问题