java - Does it make a difference to declare a logger in all uppercase and make it final? -


There is a reason to do this:

  private constant last logger LOGGER = logger GetLogger (Main.class);  

Instead of this?

  Private Static Logger Logger = LoggerFactory.getLogger (Main.class);  

I do not follow the synthetic benefits of what one is above the other, both work fine.

This C / C + constant is all uppercase names , from Java, near the constant Equivalent stable final , these members are often given the same name.

In this case, distinction can not be so important, because logger objects are not semantically static . Even then, it is still recommended to declare them as stable to ensure that your copy is an example, and you want them to be final To make sure the reference of the object is confirmed

Update to @Monkader's comment:

  1. Stable C ++ (class) is equivalent to static - as well as a great deal of meaning in C ++ which is your constant Su-stable as stated, is not it also make sense in Java.

  2. is the last not c ++ const . This means that the context in question can not be changed. However, it prevents referencing objects from changing! So it only works as a console, if it preserves the context of a primitive value (such as int ) or an immovable object (such as string ). To stay with our current topic,

    personalized last logger logger = loggerfrenchure Consider the Metallogger (Main Class); ... logger.system level (level.info); Logger.addAppender (...); Logger.setAdditivity (false);

Obviously, these calls are changing the status of the logger, although it has been declared as final . This means that I have been told above that the logar objects are not semantically stable.


Comments