Java Method Call invoke(Object o, String name)

Here you can find the source of invoke(Object o, String name)

Description

Invoke zero parameter method name.

License

Open Source License

Parameter

Parameter Description
o not null
name not null

Return

o.name()

Declaration

public static Object invoke(Object o, String name) 

Method Source Code


//package com.java2s;
/*//from w  w w .ja  v a 2  s .c  o  m
 * Copyright (c) TESOBE Ltd.  2017. All rights reserved.
 *
 * Use of this source code is governed by a GNU AFFERO license that can be found in the LICENSE file.
 *
 */

import java.lang.reflect.Method;

public class Main {
    /**
     * Invoke zero parameter method name.
     *
     * @param o not null
     * @param name not null
     *
     * @return o.name()
     */
    public static Object invoke(Object o, String name) {
        try {
            Method method = o.getClass().getMethod(name);

            method.setAccessible(true);

            return method.invoke(o);
        } catch (Exception e) {
            return null;
        }
    }
}

Related

  1. invoke(Object methodHostInstance, String methodName, Class[] parameterTypes, Object[] args)
  2. invoke(Object o, Method m)
  3. invoke(Object o, Method method, Object... param)
  4. invoke(Object o, String m, Object... params)
  5. invoke(Object o, String method, Object... args)
  6. invoke(Object o, String name, Object[] args)
  7. invoke(Object o, String name, Object[] args)
  8. invoke(Object obj, Method method, Object[] args)
  9. invoke(Object obj, Method method, Object[] params)