I use log4j for logging and tend to include the following snipet in
all my classes...
public class MyClass {
// Logging Declarations
private static String _className;
private static Category _cat;
static {
_className = MyClass.class.getName();
_cat = Category.getInstance(_className);
}
............
}
this works fine until you start to investigate obfuscation and in
particular RetroGuard; Retroguard correctly changes MyClass to be
some funny name but when the code executes the static initialiser
fails with ClassNotFoundException since MyClass.class.getName is not
myFunnyName.class.getName
What I really want is a way in a static intialiser to get .class but I
don't have a this so can't do a this.class. Any ideas?
I have a horrible hack... create a funny Constructor and create an
instance using the funny Constructor;then discard the instance.
e.g.
public class MyClass {
// Logging Declarations
private static String _className;
private static Category _cat;
static {
_className = new MyClass(_cat).class.getName();
_cat = Category.getInstance(_className);
}
private MyClass(Category c) {}
............
}
but I don't like it...
So the big question is... How do I get .class in a static context?
Thanks,
Gavin