Java Reflection Method Get from Object getMethod(Object obj, String fieldName)

Here you can find the source of getMethod(Object obj, String fieldName)

Description

Get a field in an object.

License

Open Source License

Parameter

Parameter Description
obj the object to look at.
fieldName the name of the field in the object.

Exception

Parameter Description
BuildException if there is an error.

Return

the value of the field.

Declaration

public static Method getMethod(Object obj, String fieldName) 

Method Source Code

//package com.java2s;

import java.lang.reflect.Method;

public class Main {
    /**/*from w w  w .j av a2 s .  c  om*/
     * Get a field in an object.
     * 
     * @param obj the object to look at.
     * @param fieldName the name of the field in the object.
     * @return the value of the field.
     * @throws BuildException if there is an error.
     */
    public static Method getMethod(Object obj, String fieldName) {
        try {
            Method method = obj.getClass().getMethod("get" + fieldName);
            return method;
        } catch (Exception t) {
            return null; // NotReached
        }
    }
}

Related

  1. getMethod(Object instance, String methodName, Class[] parameters)
  2. getMethod(Object o, String methodName)
  3. getMethod(Object o, String methodName, Class[] args)
  4. getMethod(Object o, String methodName, Class[] paramTypes)
  5. getMethod(Object obj, Class[] paramTypes, String methodName)
  6. getMethod(Object obj, String methodName)
  7. getMethod(Object obj, String methodName, Class paramClass)
  8. getMethod(Object obj, String methodName, Class... parameterTypes)
  9. getMethod(Object obj, String name, Class... types)