Hi, I was wondering if anone here could help me out a bit with my Reflection problem. My problem is that when I try to find the methods
inside a class, not only do I get its methods, but all of its inherited methods or something like that. So if I ran the below code (Example being a made up class with a couple of methods):

Class getclass = Class.forName(Example);
Object a[] = getclass.getMethods();
for (int i = 0; i < a.length; i++) {
   System.out.println (a[i]);

I'd get the first two output as:
public int Example.add(int,int)
public void Example.output()

then the rest would be:
public native int java.lang.Object.hashCode()
public final native java.lang.Class java.lang.Object.getClass()
public final void java.lang.Object.wait() throws java.lang.InterruptedException
public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException
public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException
public boolean java.lang.Object.equals(java.lang.Object)
public final native void java.lang.Object.notify()
public final native void java.lang.Object.notifyAll()
public java.lang.String java.lang.Object.toString()

Which I don't really want to be getting. Is there anyway I could make it so that getmethods() just gets the primary methods? Also, just a sidenote, what's a Field?

use getDeclaredMethods() instead.

The API docs would have told you as much :) (yes, I know I keep hammering away at people using them, they're that good) :mrgreen:

Ahhhhh XD thanks very much. I had read the API before, but I have a lot of trouble understanding the detailed terminology, so usually the API goes right over my head. Speaking of that, does anyone know what a field is? :X

This article has been dead for over six months. Start a new discussion instead.