Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I get all methods of a class?

Suppose that I have a .class file, can I get all the methods included in that class ?

like image 549
Eng.Fouad Avatar asked Mar 10 '11 22:03

Eng.Fouad


People also ask

How do you get all methods in a class?

Method 1 – Using the dir() function to list methods in a class. To list the methods for this class, one approach is to use the dir() function in Python. The dir() function will return all functions and properties of the class. Let's see what happens if we try it for MyClass .

How do I see all methods in Python?

You can use the built in dir() function to get a list of all the attributes a module has. Try this at the command line to see how it works. Also, you can use the hasattr(module_name, "attr_name") function to find out if a module has a specific attribute. See the Guide to Python introspection for more information.

How many methods of class are there?

There are basically three types of methods in Python: Instance Method. Class Method. Static Method.

How many methods can a class have in Python?

Inside a Class, we can define the following three types of methods.


1 Answers

Straight from the source: http://java.sun.com/developer/technicalArticles/ALT/Reflection/ Then I modified it to be self contained, not requiring anything from the command line. ;-)

import java.lang.reflect.*;  /**  Compile with this: C:\Documents and Settings\glow\My Documents\j>javac DumpMethods.java  Run like this, and results follow C:\Documents and Settings\glow\My Documents\j>java DumpMethods public void DumpMethods.foo() public int DumpMethods.bar() public java.lang.String DumpMethods.baz() public static void DumpMethods.main(java.lang.String[]) */  public class DumpMethods {      public void foo() { }      public int bar() { return 12; }      public String baz() { return ""; }      public static void main(String args[]) {         try {             Class thisClass = DumpMethods.class;             Method[] methods = thisClass.getDeclaredMethods();              for (int i = 0; i < methods.length; i++) {                 System.out.println(methods[i].toString());             }         } catch (Throwable e) {             System.err.println(e);         }     } } 
like image 150
corsiKa Avatar answered Oct 28 '22 23:10

corsiKa