Why we should not use protected static in java

前端 未结 8 2009
醉梦人生
醉梦人生 2020-11-29 17:01

I was going through this question Is there a way to override class variables in Java? The first comment with 36 upvotes was:

If you ever see a p

8条回答
  •  时光说笑
    2020-11-29 17:15

    Actually there is nothing fundamentally wrong with protected static. If you really want a static variable or method that is visible for the package and all subclasses of the declaring class then go ahead and make it protected static.

    Some people generally avoid to use protected for various reasons and some people think non-final static variables should be avoided by all means (I personally sympathize with the latter to some degree), so I guess the combination of protected and static must look bad^2 to those that belong to both groups.

提交回复
热议问题