'public static final' or 'private static final' with getter?

前端 未结 7 1978
花落未央
花落未央 2020-12-23 00:05

In Java, it\'s taught that variables should be kept private to enable better encapsulation, but what about static constants? This:

public static final int FO         


        
相关标签:
7条回答
  • 2020-12-23 00:27

    I'd stay with the getFoo() since it allows you to change the implementation in the future without changing the client code. As @Tomasz noted, the JVM will probably inline your current implementation, so you pay much of a performance penalty.

    0 讨论(0)
提交回复
热议问题