Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

reflection API problem

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi..
I have a serious problem...
I am making a tool that will dynamicallly load the classes inside a dir strcuture to find the name of a class that has the declaration of a method.I am using the Reflection API...But it has become very slow....

Please suggest

private void findMethod(String mthdname, File pckg) {
File files[] = pckg.listFiles();

for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
findMethod(mthdname,files[i]);
} else {
if (files[i].getName().endsWith(".class")) {
try {
String classnme = files[i].getName();
int indexofclass = classnme.indexOf(".class");
Class classname = Class.forName(classnme.substring(0, indexofclass));
Method[] methods = classname.getDeclaredMethods();
for (int j = 0; j < methods.length; j++) {
String methodname = methods[j].getName();
if (methodname.equals(mthdname)) {
boolean nopackage = false;
try {
targetname = methods[j].getDeclaringClass().getName();
targetpackage = methods[j].getDeclaringClass().getPackage().getName();
} catch (NullPointerException nullpointer) {
nopackage = true;
} finally {
if (!nopackage)
System.out.println("Package name: " + targetpackage);
System.out.println("Class name: " + targetname);
return;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

}
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi Pinjalim,
Your question was answered here, so I am closing this thread. Please don't start the same topic in more than one forum; it wastes time for people who don't realize if something's already been answered elsewhere. Thanks!
 
Destiny's powerful hand has made the bed of my future. And this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
    Bookmark Topic Watch Topic
  • New Topic