Passing MethodHandles.lookup().lookupClass() vs passing Class<?> to getLogger method

Viewed 1172

I recently came across a logger declared as below:

private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

Is there an advantage to declaring the logger in this manner as opposed to declaring it 'normally' like this:

`private static final Logger logger = LoggerFactory.getLogger(MyClass.class`);
1 Answers

Using MethodHandles.lookup().lookupClass() avoids embedding the class name, which will often be wrong when the line is copyed and pasted.

Related