samedi 6 janvier 2018

Java Reflection getting methods

I want to create Class object and get all methods of this class to Method[]. But I don't know how to do it. I've tried something like Class.forName(), it didn't work.

   public static ClassInformation createFully(String jarName, String    className) throws IOException, ClassNotFoundException {
       URL u = new URL("jar:file:" + jarName + "!/" + className);
       InputStream in = u.openConnection().getInputStream();
       BufferedInputStream bin = new BufferedInputStream(in);
       DataInputStream din = new DataInputStream(bin);

       ClassInformation classInfo = new ClassInformation(jarName,    className);

       if (className.endsWith(".class"))
       {
           classFile classFile = new classFile(din);
           classInfo.setModifiers(classFile.getClassModifiers());
           classInfo.setConstructors(classFile.getConstructors());
           classInfo.setFields(classFile.getFields());
           classInfo.setInterfaces(classFile.getInterfaces());
           classInfo.setMethods(classFile.getMethods());
           classInfo.setSuperclass(classFile.getSuperClassName());
       }


       return classInfo;

   }





Aucun commentaire:

Enregistrer un commentaire