Package Name As A Constant
Join the DZone community and get the full member experience.Join For Free
getClass().getPackage().getName() is not a reliable solution, because getPackage() can be null depending on a class loader.
static final String PACKAGE_NAME = MyClass.class.getName().substring(0, MyClass.class.getName().lastIndexOf('.'));
Opinions expressed by DZone contributors are their own.