Can I take a string that has a class name and create a new class from it? I can do this in C# but I have no idea how to do so with Java.
Name:
Anonymous2009-01-26 19:49
new JavaVirtualMachine.ClassFactory(new DynamicClassRunTimeEvalutation(className), JavaVirtualMachine.getFactoryInstance().CONSTANT_LOAD_CLASS_FAILSAFE);
Name:
Anonymous2009-01-26 20:01
Hmm, how do I use that in eclipse? Google didn't help.
Okay I'm doing this:
Class.forName(somename).getConstructor().newInstance(x, y, somecustomclass);
but I'm getting back this:
java.lang.NoSuchMethodException: ((somename's contents, it's a valid class)).<init>()
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getConstructor(Unknown Source)
There is a public constructor and it does accept those parameters, so I'm still lost(but hopefully really close).
Name:
Anonymous2009-01-26 21:00
>>6
You have to specify which constructor you want with the call to getConstructor.
OP back for one more question, if this is possible my project will have the best modularity I can manage. Can I get a list of classes that extend another class?
Name:
Anonymous2009-01-26 22:38
Or, I suppose, all classes in the current package that are instanceof the super class
Name:
Anonymous2009-01-26 23:54
I take it from the lack of response in over an hour that there's no way to do this?