Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Java, is this possible?

Name: Anonymous 2009-01-26 19:43

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: Anonymous 2009-01-26 19:49

new JavaVirtualMachine.ClassFactory(new DynamicClassRunTimeEvalutation(className), JavaVirtualMachine.getFactoryInstance().CONSTANT_LOAD_CLASS_FAILSAFE);

Name: Anonymous 2009-01-26 20:01

Hmm, how do I use that in eclipse? Google didn't help.

Name: Anonymous 2009-01-26 20:02

Class.forName('HMAFactory').getConstructor().newInstance()

Name: Anonymous 2009-01-26 20:17

Class.forName('AnusFactory').getConstructor().newInstance().hax()

Name: Anonymous 2009-01-26 20:55

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: Anonymous 2009-01-26 21:00

>>6
You have to specify which constructor you want with the call to getConstructor.

Name: Anonymous 2009-01-26 21:13

>>7
(+5, Informative)

Name: Anonymous 2009-01-26 21:47

>>6
If you're running Java >= 5.0 (which you are), it is easier to do this:
SomeClass.class.getConstructor(params).newInstance(args)

Then you don't have to worry about fucking up Class.forName(String).

Name: Anonymous 2009-01-26 21:58

>>9
Are you illiterate?

Name: Anonymous 2009-01-26 22:05

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: Anonymous 2009-01-26 22:38

Or, I suppose, all classes in the current package that are instanceof the super class

Name: Anonymous 2009-01-26 23:54

I take it from the lack of response in over an hour that there's no way to do this?

Name: Anonymous 2009-01-27 0:09

>>10
FAG

Name: Anonymous 2009-01-27 2:01

Well, my little project is finally done, thanks for your help:
>>4
>>7

Name: Anonymous 2009-03-06 6:38

The program INSIDE malloc!

Name: ​​​​​​​​​​ 2010-10-21 14:39

Name: Anonymous 2011-02-04 19:42

Name: Anonymous 2013-09-01 14:18





    Think of useing a usd, as a mental tax wright-off using it as toilet paper. To most people its worth the same amount as before worn down threw a dishwasher.

Name: Anonymous 2013-09-01 15:49


お待ちしております、
ここに書いてね

Don't change these.
Name: Email:
Entire Thread Thread List