Reputation: 21
The purpose of the code here is to compile a class that was created on a .java file so that it could tell if the users input was correct. However the code returns false with every trial.
import java.lang.*;
/**
* @author Joey
*/
public class NewCompTets {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
NewCompTets cls = new NewCompTets();
NewCompTets subcls = new SubClass1();
// class CompilerDemo
Class c = cls.getClass();
System.out.println(c);
// sub class SubClass1
Class c1 = subcls.getClass();
System.out.println(c1);
/* returns false if the compilation failed or no compiler is
available */
boolean retval = Compiler.compileClass(c1);
System.out.println("Return Value = " + retval);
}
}
class SubClass1 extends NewCompTets {
public static void test(){
System.out.print("2");
}
}
Upvotes: 0
Views: 115
Reputation: 785
I suppose you always need to compile the parent class first, then you can compile the child classent class then you can compile the child class.
Upvotes: 0