Z
zero
I'm trying to figure out reflection, and I've run into a problem. In the
code below the JFrame and String get instantiated fine, but MyClass gives
an InstantiationException.
What am I overlooking here?
import java.util.ArrayList;
public class ReflectionTest
{
public static void main(String[] args) throws Exception
{
ArrayList<String> typeNames = new ArrayList<String>();
typeNames.add(String.class.getName());
typeNames.add(javax.swing.JFrame.class.getName());
// typeNames.add(MyClass.class.getName());
ArrayList<Object> data = new ArrayList<Object>();
for(String name : typeNames)
data.add(Class.forName(name).newInstance());
System.out.println(data.toString());
}
private class MyClass
{
public MyClass()
{
super();
}
public String toString()
{
return "MyClass";
}
}
}
code below the JFrame and String get instantiated fine, but MyClass gives
an InstantiationException.
What am I overlooking here?
import java.util.ArrayList;
public class ReflectionTest
{
public static void main(String[] args) throws Exception
{
ArrayList<String> typeNames = new ArrayList<String>();
typeNames.add(String.class.getName());
typeNames.add(javax.swing.JFrame.class.getName());
// typeNames.add(MyClass.class.getName());
ArrayList<Object> data = new ArrayList<Object>();
for(String name : typeNames)
data.add(Class.forName(name).newInstance());
System.out.println(data.toString());
}
private class MyClass
{
public MyClass()
{
super();
}
public String toString()
{
return "MyClass";
}
}
}