Say we have a class "MyClassToCheck" with code below.
From another application I want to check if the class' method signatures conform to a certain spec without having all dependencies needed. (as indicated by "ClassNotOnClasspath").
In this App I load the class with "forName" and then call getMethods() on it.
ClassNotOnClassPath instance_member1=new ClassNotOnClassPath();; // --> WORKS !!
//static ClassNotOnClassPath static_member1=new ClassNotOnClassPath(); // --> DOES NOT WORK which is comprehensible!!
public RetValOnClassPath myMethodName( ParamOnClassPath par1, AnotherParamOnClassPath par2)
ClassNotOnClassPath local=new ClassNotOnClassPath(); // --> WORKS !!
So I had thought too.
But it does matter.
Some more experiments showed that Class.forName fails on code containing a var decl using an unresolvable class in a try block if that code was compiled with Java 1.4 or Java 5. It does not fail when the code is compiled with J6 or 7. Must have something to do with the bytecode definition. Have tried only with Sun/Oracle Java compilers/VMs and Eclipse's built in JDT compiler/generator.