Use member methods in the Java language to correspond to the behavior of class objects. Take the Book class as an example. It includes two methods: getName() and setName(), which are to get the book name and set the book name.
Explanation
1. Class member methods are objects of java.lang.reflect.Method.
2. You can obtain the class member methods through the java.lang.Class class, or you can call the obtained member methods through the methods provided by the class Method.
Example
public Method getDeclaredMethod(String name, Class<?>... parameterTypes) // 得到该类所有的方法,不包括父类的 public Method getMethod(String name, Class<?>... parameterTypes) // 得到该类所有的public方法,包括父类的 //具体使用 Method[] methods = class1.getDeclaredMethods();//获取class对象的所有声明方法 Method[] allMethods = class1.getMethods();//获取class对象的所有public方法 包括父类的方法 Method method = class1.getMethod("info", String.class);//返回此class1对应的public修饰的方法名是info的,包含一个String类型变量的方法 Method declaredMethod = class1.getDeclaredMethod("info", String.class);//返回此Class对象对应类的、带指定形参列表的方法
Java is mainly used in:
1.web development;
2. Android development;
3. Client development;
4. Web development;
5. Enterprise application development;
6. Java big data development;
7. Game development, etc.
The above is the detailed content of Detailed explanation of how to use Java member methods. For more information, please follow other related articles on the PHP Chinese website!