Reflection in Python

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2005
Posts: 23
Reputation: Rete is an unknown quantity at this point 
Solved Threads: 1
Rete Rete is offline Offline
Newbie Poster

Reflection in Python

 
0
  #1
Aug 4th, 2005
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):

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


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?
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Reflection in Python

 
0
  #2
Aug 4th, 2005
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:
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 23
Reputation: Rete is an unknown quantity at this point 
Solved Threads: 1
Rete Rete is offline Offline
Newbie Poster

Re: Reflection in Python

 
0
  #3
Aug 4th, 2005
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?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum


Views: 3019 | Replies: 2
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC