Java: Load class from string
I know this has probably something to do with class loaders, however I couldn't find an example (it might be I'm google-ing for the wrong keywords. I am trying to load a class (or a method) form a string. The string doesn't contain the name of a class, but the code for a class, e.g. class MyClass implements IMath { public int add(int x, int y) { return x + y; } } and then do something like this: String s = "class MyClass implements IMath { public int add(int x, int y) { return x + y; }}"; IMath loadedClass = someThing.loadAndInitialize(string); int result = loadedClass.add(5,6); Now obviously,