English 中文(简体)
财产或Enum或静态定本
原标题:Properties or Enums or static final

当有人以姓氏价值为平价宣布预先确定的固定不变时,我被随意选择在javautil之间。 具有公共静态最终价值的财产、财产或单独类别。

For future reference, I need some guidelines over which approach to take.

感谢!

最佳回答

It all depends of your constant lifecycle. Constant are by definition something that do not move. Choosing the right methods will be a question of the likely to change and the repackaging need.

  • 如果你真心实意地相信,它就取得了前所未有的进展:静态最终是前进的道路。 缩略语

  • 如果你认为存在潜在的变化,但需要易于操作密码,并且不担心会晚相容,那么 en就 。 我在一段时间前就这样说了。

  • 如果你认为存在潜在的变化,但你不希望这种变化影响你的规范,财产(有资源障碍)是更好的选择。 标签(翻译)、内乱环境等也是一个很好的例子。

问题回答

在您不能形成一套可以选择变量状态的封闭式选择时,使用“密码”最后。 相反,在你能够的时候,你总是使用 en。

现在,如果你想要保留关键价值的字典,而不管其性质如何,它需要时间使用一种类型的物,有时是地图。

还有一点需要考虑——这些力量是否在不同版本中发生变化? i.e. 是否有法语版本、中文版本、“先进”版本? 如果是的话,财产/财产等是走路。

固定不变值时使用Enums,预计不会经常改变。 如果经常发生变化,则难以保持与你以前的版本的后向兼容性。 如果在客户服务器结构中都有不同版本的Enum。 E.g

Server : public enum Priority{ HIGH,LOW,MEDIUM,AVERAGE}

Client : public enum Priority{ HIGH,LOW,MEDIUM}

如果服务器发出优先权,请说。 然后,客户的“电子通话”就会成为例外。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签