Java.lang.nosuchmethodexception:com.tanke.pojo.timetankproxy.<init> (Com.tanke.pojo.Tank)
At Java.lang.Class.getConstructor0 (class.java:2706)
At Java.lang.Class.getConstructor (class.java:1657)
At Com.tanke.test.Main.main (main.java:82)
url[] urls = new Url[]{new URL ("file:/" +system.getproperty ("User.dir") + "/bin")};
URLClassLoader ul = new URLClassLoader (URLs);
Class C = Ul.loadclass ("Com.tanke.pojo.TimeTankProxy");//load Class into memory
System.out.println (C.getname ());
C.newinstance ();//This is a constructor object that generates a parameterless
Constructor ctr = C.getconstructor (Tank.class);//This type of error, even Tank implements, can not.
Constructor ctr = C.getconstructor (Moveable.class);//construction method, Moveable.class as parameter type
Loaded into a class object
Moveable M = (moveable) ctr.newinstance (new Tank ());
M.move ();
ClassLoader cl = Classloader.getsystemclassloader ();
System.out.println (Cl.tostring ());
The parameters of the constructor in the following timetankproxy are moveable types, then the parameters must be moveable.class when the constructor is generated. cannot be its inheriting class or implementation class.
Package Com.tanke.pojo;
Import com.tanke.inter.Moveable;
public class Timetankproxy implements moveable {
private moveable t;
pu Blic timetankproxy (Moveable t) {
this.t = t;
}
@Override
public void Move () {
Long start = System.currenttimemillis ();
system.out.println ("Start time:" + start);
t.move ();
long end = System.currenttimemillis ();
system.out.println ("End time:" + end);
system.out.println ("Total Time:" + (End-start));
}
}