How do I retrieve a child Class for Java reflection? -


so, going sound odd question, i need know how class object of child object in inheritance situation java reflection.

the situation this: i'm writing craftbukkit plugins, java plugins work craftbukkit, server-side-only plugin a.p.i. minecraft. @ moment, i'm making plugin supposed "parent" of other plugins i'm writing. contains large amounts of useful objects , utilities.

one class in plugin object class called myplugin want main classes of other plugins extend. (i know object names shouldn't start lowercase letter, lowercase "my" trademark craftbukkit plugins.)

one of things want myplugin class able handle commands load plugins' data. therefore, when command called, i want plugin call of methods in plugin's main class start "load".

i know how search through methods in class ones starting "load" if can retrieve class, if try call getclass() in myplugin class, believe it's going return myplugin class instead of class extends myplugin.

so, how can retrieve class extends myplugin instead of myplugin class itself?

edit: feel should mention i've considered creating abstract method called mainclass() return class , making each plugin add method , return main class, ugly fix prefer avoid.

no it's subclass name returned, consider:

public class classone {  }  public class classtwo extends classone {  }  public class test {      public void somemethod(classone one) {          system.out.println(one.getclass().getname());     }  }  public class main {      public static void main(string[] args) {          classtwo t = new classtwo();         test tst = new test();         tst.somemethod(t);     }  } 

the output is: classtwo


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -