Java “self” (static) reference

前端 未结 4 1206
感动是毒
感动是毒 2021-02-20 14:04

I am looking for a \"self\" reference to the current class in JAVA in a static context manner like in PHP Scope Resolution Operator?

Solution: Break out of scope? BEWARE

4条回答
  •  隐瞒了意图╮
    2021-02-20 14:30

    The slightly faster

    static final Logger LOG = LoggerFactory.getLogger(
           Thread.currentThread().getStackTrace()[0].getClassName());
    

    If you do this 1000 times it will take 36 ms using Class.class.getName() and 60 ms doing it this way. Perhaps its not worth worrying about too much. ;)

提交回复
热议问题