Example usage for com.badlogic.gdx.utils.reflect Method isAccessible

List of usage examples for com.badlogic.gdx.utils.reflect Method isAccessible

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils.reflect Method isAccessible.

Prototype

public boolean isAccessible() 

Source Link

Usage

From source file:com.github.ykrasik.jaci.util.reflection.ReflectionUtils.java

License:Apache License

/**
 * Invokes the method, using the provided instance as 'this'.
 * Method must be no-args and have a return value of type {@code T}.
 * If the method is private, it will be made accessible outside of it's class.
 *
 * @param instance Instance to use as 'this' for invocation.
 * @param method Method to invoke.//from w  ww . j a v  a 2 s  . com
 * @param <T> Return type.
 * @return Result of invoking the no-args method.
 * @throws RuntimeException If an error occurred invoking the method.
 */
@SuppressWarnings("unchecked")
public static <T> T invokeNoArgs(Object instance, Method method) {
    try {
        if (!method.isAccessible()) {
            method.setAccessible(true);
        }
        return (T) method.invoke(instance, NO_ARGS);
    } catch (final java.lang.Throwable $ex) {
        throw new RuntimeException($ex);
    }
}