| | As you may or may not know, there's a java.lang.Class class which handles stuff that's pretty cool. You can use it to get the methods of a class, constructors of a class, etc. Anyway, I'm kind of interested in making a simple Java interpreter, and if I were able to cast a String that contains the name of a class into a Class object, it would make that project infinitely easier. The most obvious thing would be to use a Class object constructor, but there aren't any. So basically, I want to do something like this: CODE String s = "System"; Class c = (Class)s; //not sure if this works Method m = c.getMethod("currentTimeMillis", new Class[0]); long n = m.invoke(null, new Object[0]); //etc. I'm not sure if the line (that has been clearly labeled) works, though. If anyone knows if this does or doesn't work and can suggest an alternative if it doesn't, the help would be greatly appreciated. |


