Properties file vs Constants class in Java

前端 未结 8 1238
臣服心动
臣服心动 2020-12-16 11:03

I am a bit confused between using a constants file and properties file in Java.

How to decide when to use Constants.java and when to use a .properties

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-16 11:41

    Generally, anything in a constants class is considered to be "hardcoded"; that is, you are required to re-compile to make changes.

    Use a .properties file for things like configuration, where you don't have to be forced to re-compile just to make changes. In this way, you can simply change the properties file and restart your application.

提交回复
热议问题