try
{
Class.forName(class name as string)
}
catch(ClassNotFoundException e)
{
whatever
}
That should do it.
@Longpoke
Maybe I am misunderstanding something then. Can you create an example where a class is loaded but the static initializer is not executed? Here is an example that does nothing but print out that it has loaded:
package test;
public class TestStatic
{
public static void main(String[] args)
{
try
{
Class.forName("test.Static");
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
}
}
With the following Static class being loaded:
package test;
public class Static
{
static
{
System.out.println("Static Initializer ran...");
}
}
If the static initializers are not ran until the conditions you listed are met then why does this println get executed when I run my test? That is which of your listed conditions am I meeting?