Quantcast
Channel: Active questions tagged methodhandle - Stack Overflow
Viewing all articles
Browse latest Browse all 36

Constants that use other constants in Java

$
0
0

In my class, I need both an SLF4J Logger with the class as the parameter, as well as a simple class name. Both the logger and CLASS_NAME constants use MethodHandles.lookup(). I was wondering if it makes more sense/is more efficient to have something like this:

private static final Lookup lookup = MethodHandles.lookup();private static final Logger logger = LoggerFactory.getLogger(lookup.getClass());private static final String CLASS_NAME = lookup.lookupClass().getSimpleName();

Or just have MethodHandles.lookup() twice:

private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().getClass());private static final String CLASS_NAME = MethodHandles.lookup().lookupClass().getSimpleName();

Viewing all articles
Browse latest Browse all 36

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>