public Class<?> compile(String className,String code){
  try {
    JavaFileObject sourceFile=new StringJavaFileObject(className,code);
    compileClass(sourceFile);
    return classLoader.loadClass(className);
  }
 catch (  ClassNotFoundException e) {
    throw new AssertionError("Failed to load newly compiled class:\n" + e.toString());
  }
catch (  IOException e) {
    throw new AssertionError("Failed to write file:\n" + e.toString());
  }
}

public Class < ? > compile ( String className , String code ) { try { JavaFileObject sourceFile = new StringJavaFileObject ( className , code ) ; compileClass ( sourceFile ) ; return classLoader . loadClass ( className ) ; } catch ( ClassNotFoundException e ) { throw new AssertionError ( "Failed to load newly compiled class:\n" + e . toString ( ) ) ; } catch ( IOException e ) { throw new AssertionError ( "Failed to write file:\n" + e . toString ( ) ) ; } }
compiles the class . the class must be in the default package .
