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

Pages: 1-

The relative merits of the reflection

Name: Anonymous 2010-11-11 12:46


// Without reflection
Foo foo = new Foo();
foo.hello();


Well, now that was lame as fuck.

_______________________________________________


// With reflection
Class cls = Class.forName("Foo");
Object foo = cls.newInstance();
Method method = cls.getMethod("hello", null);
method.invoke(foo, null);


Now that's what I call elegant!

Name: Anonymous 2010-11-11 12:52

NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL

Name: Anonymous 2010-11-11 14:09

Reflection is great in a REPL. I've never found it appealing to use reflection in actual code though.

Name: Anonymous 2010-11-11 16:52

>>1

Class cls = Class.forName("Person");
Object me = cls.newInstance();
Object anus = cls.getMethod("getAnus", null).invoke(me, null);
print(Class.forName("Anus").getMethod("reflect", null).invoke(anus);

Output:
REFLECT MY ANUS

Name: Anonymous 2010-11-11 16:54

>>4
*[code]print(Class.forName("Anus").getMethod("reflect", null).invoke(anus, null));

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