[Java] define Logger Why use static and final?

private static final Logger logger= LoggerFactory.getLogger(ShiroConfig.class);

(1) resource utilization considerations, Logger constructor arguments are Class, Logger is determined according to the log to distinguish the class structure, so long as a class can be a Logger, and it is static

(2) final represents a programming habits, it represents the class Logger class information recording only, otherwise the log will not provide a convincing record

  • Defined as static final, logger immutable variables, faster read speed
  • static variables are modified to create a new no matter how many instances, only created once, saving space, if every time create more waste then Logger memory; final modification representation can not be changed, the constant
  • Is defined as the static field, only one of each class of such field. And each object has its own copy of all instance fields., Static modification with both space-saving and efficiency is good. This final logger is no longer pointing to other objects Logger

 

Guess you like

Origin www.cnblogs.com/jxd283465/p/11726678.html