Why private method can not be final as well?

前端 未结 3 1197
难免孤独
难免孤独 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:59

    One edge case that requires a private method to be final is when the SafeVarargs annotation is used. The following code does not compile, because the private method is not final.

    @SafeVarargs
    private void method(List... stringLists) {
        //TODO a safe varargs operation
    }
    

提交回复
热议问题