当前位置: 首页>>代码示例>>Java>>正文


Java Method类代码示例

本文整理汇总了Java中java.lang.reflect.Method的典型用法代码示例。如果您正苦于以下问题:Java Method类的具体用法?Java Method怎么用?Java Method使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Method类属于java.lang.reflect包,在下文中一共展示了Method类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: speedUpDtmManager

import java.lang.reflect.Method; //导入依赖的package包/类
/**
 * Used to optimize performance by avoiding expensive file access every time
 * a DTMManager is constructed as a result of constructing a Xalan xpath
 * context!
 */
private static void speedUpDtmManager() throws Exception {
    // https://github.com/aws/aws-sdk-java/issues/238
    // http://stackoverflow.com/questions/6340802/java-xpath-apache-jaxp-implementation-performance
    // CHECKSTYLE:OFF - We need to load system properties from third-party libraries.
    if (System.getProperty(DTM_MANAGER_DEFAULT_PROP_NAME) == null) {
        // CHECKSTYLE:ON
        Class<?> xPathContextClass = Class.forName(XPATH_CONTEXT_CLASS_NAME);
        Method getDtmManager = xPathContextClass.getMethod("getDTMManager");
        Object xPathContext = xPathContextClass.newInstance();
        Object dtmManager = getDtmManager.invoke(xPathContext);

        if (DTM_MANAGER_IMPL_CLASS_NAME.equals(dtmManager.getClass().getName())) {
            // This would avoid the file system to be accessed every time
            // the internal XPathContext is instantiated.
            System.setProperty(DTM_MANAGER_DEFAULT_PROP_NAME,
                               DTM_MANAGER_IMPL_CLASS_NAME);
        }
    }
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:25,代码来源:XpathUtils.java

示例2: newProxy

import java.lang.reflect.Method; //导入依赖的package包/类
private static <I> I newProxy(final Class<I> interfaceType) {
	Object o = new Object();

	Method getOriginal;
	try {
		getOriginal = ProxyContainer.class.getMethod("getOriginal");
	} catch (NoSuchMethodException | SecurityException e) {
		throw new AssertionError(e);
	}

	I proxyInstance = newProxy(interfaceType, new Class<?>[] { ProxyContainer.class }, (proxy, method, args) -> {
		if (getOriginal.equals(method)) {
			return o;
		}

		for (int i = 0; i < args.length; i++) {
			if (args[i] instanceof ProxyContainer) {
				args[i] = ((ProxyContainer) args[i]).getOriginal();
			}
		}
		return method.invoke(o, args);
	});
	return proxyInstance;
}
 
开发者ID:future-architect,项目名称:uroborosql,代码行数:25,代码来源:DoubleArrayParameterMapperTest.java

示例3: getTreeItemForMethod

import java.lang.reflect.Method; //导入依赖的package包/类
private AssertionTreeItem getTreeItemForMethod(Object object, Method method) {
    boolean accessible = method.isAccessible();
    try {
        method.setAccessible(true);
        Object value = method.invoke(object, new Object[] {});
        if (value != null) {
            if (value.getClass().isArray())
                value = RFXComponent.unboxPremitiveArray(value);
            return new AssertionTreeItem(value, getPropertyName(method.getName()));
        }
    } catch (Throwable t) {
    } finally {
        method.setAccessible(accessible);
    }
    return null;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:17,代码来源:AssertionTreeView.java

示例4: testStaticInvoke1

import java.lang.reflect.Method; //导入依赖的package包/类
@Test
public void testStaticInvoke1() throws Throwable {
    Method method = CountClass.class.getMethod("count");
    int x1, x2, x3;
    method.invoke(count);

    x1 = invoke(method, null);
    x2 = invoke(method, null);
    x3 = invoke(method, null);
    Assert.assertEquals(x1, x2);
    Assert.assertEquals(x1, x3);

    method = CountClass.class.getMethod("count", int.class);
    int X1, X2, X3, X4;

    X1 = invoke(method, new Object[]{1000});
    X2 = invoke(method, new Object[]{2000});
    X3 = invoke(method, new Object[]{1000});
    X4 = invoke(method, new Object[]{2000});
    Assert.assertEquals(X1, X3);
    Assert.assertEquals(X2, X4);

}
 
开发者ID:alibaba,项目名称:jetcache,代码行数:24,代码来源:CacheHandlerTest.java

示例5: verifyPureArguments

import java.lang.reflect.Method; //导入依赖的package包/类
private static WebException verifyPureArguments(
        final Validator verifier,
        final Depot depot,
        final Object[] args) {
    final Event event = depot.getEvent();
    final Object proxy = event.getProxy();
    final Method method = event.getAction();
    WebException error = null;
    try {
        if (Virtual.is(proxy)) {
            // TODO: Wait for proxy generation
            // Validation for dynamic proxy
            // final Object delegate = Instance.getProxy(method);
            // verifier.verifyMethod(delegate, method, args);
        } else {
            // Validation for proxy
            verifier.verifyMethod(proxy, method, args);
        }
    } catch (final WebException ex) {
        // Basic validation failure
        error = ex;
    }
    return error;
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:25,代码来源:Flower.java

示例6: onLoadingFinish

import java.lang.reflect.Method; //导入依赖的package包/类
@Override
public AnimatorUpdateListener onLoadingFinish(int footerHeight, Interpolator interpolator, int duration) {
    if (mScrollableView != null) {
        if (mScrollableView instanceof RecyclerView) ((RecyclerView) mScrollableView).smoothScrollBy(0, footerHeight, interpolator);
        else if (mScrollableView instanceof ScrollView) ((ScrollView) mScrollableView).smoothScrollBy(0, footerHeight);
        else if (mScrollableView instanceof AbsListView) ((AbsListView) mScrollableView).smoothScrollBy(footerHeight, duration);
        else {
            try {
                Method method = mScrollableView.getClass().getDeclaredMethod("smoothScrollBy", Integer.class, Integer.class);
                method.invoke(mScrollableView, 0, footerHeight);
            } catch (Exception e) {
                int scrollX = mScrollableView.getScrollX();
                int scrollY = mScrollableView.getScrollY();
                return animation -> mScrollableView.scrollTo(scrollX, scrollY + (int) animation.getAnimatedValue());
            }
        }
        return null;
    }
    return null;
}
 
开发者ID:Brave-wan,项目名称:SmartRefresh,代码行数:21,代码来源:RefreshContentWrapper.java

示例7: invokeMethod

import java.lang.reflect.Method; //导入依赖的package包/类
public static Object invokeMethod(Method method, Object methodReceiver, Object... methodParamValues) throws
        InvocationTargetException, IllegalAccessException {

    if (method != null) {
        boolean acc = method.isAccessible();

        if (!acc) {
            method.setAccessible(true);
        }

        Object ret = method.invoke(methodReceiver, methodParamValues);

        if (!acc) {
            method.setAccessible(false);
        }

        return ret;
    }

    return null;
}
 
开发者ID:wangyupeng1-iri,项目名称:springreplugin,代码行数:22,代码来源:ReflectUtils.java

示例8: beforeInvoke

import java.lang.reflect.Method; //导入依赖的package包/类
@Override
protected boolean beforeInvoke(Object receiver, Method method, Object[] args) throws Throwable {
    //2.3,15,16,17,18,19,21
/* public void grantUriPermissionFromOwner(IBinder owner, int fromUid, String targetPkg,
    Uri uri, int mode) throws RemoteException;*/
    //这个函数是用来给某个包授予访问某个URI的权限。
    //插件调用这个函数会传插件自己的包名,而此插件并未被安装。就这样调用原来函数传给系统,是会出问题的。所以改成宿主程序的包名。
    final int index = 2;
    if (args != null && args.length > index) {
        if (args[index] != null && args[index] instanceof String) {
            String targetPkg = (String) args[index];
            if (isPackagePlugin(targetPkg)) {
                args[index] = mHostContext.getPackageName();
            }
        }
    }

    return super.beforeInvoke(receiver, method, args);
}
 
开发者ID:amikey,项目名称:DroidPlugin,代码行数:20,代码来源:IActivityManagerHookHandle.java

示例9: executeMethod

import java.lang.reflect.Method; //导入依赖的package包/类
/**
 * Executes the method of the specified <code>ApplicationContext</code>
 * @param method The method object to be invoked.
 * @param context The AppliationContext object on which the method
 *                   will be invoked
 * @param params The arguments passed to the called method.
 */
private Object executeMethod(final Method method, 
                             final ApplicationContext context,
                             final Object[] params) 
        throws PrivilegedActionException, 
               IllegalAccessException,
               InvocationTargetException {
                                 
    if (SecurityUtil.isPackageProtectionEnabled()){
       return AccessController.doPrivileged(new PrivilegedExceptionAction<Object>(){
            @Override
            public Object run() throws IllegalAccessException, InvocationTargetException{
                return method.invoke(context,  params);
            }
        });
    } else {
        return method.invoke(context, params);
    }        
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:26,代码来源:ApplicationContextFacade.java

示例10: getItem

import java.lang.reflect.Method; //导入依赖的package包/类
public Object getItem() {
    Object newValue = editor.getText();

    if (oldValue != null && !(oldValue instanceof String))  {
        // The original value is not a string. Should return the value in it's
        // original type.
        if (newValue.equals(oldValue.toString()))  {
            return oldValue;
        } else {
            // Must take the value from the editor and get the value and cast it to the new type.
            Class<?> cls = oldValue.getClass();
            try {
                Method method = MethodUtil.getMethod(cls, "valueOf", new Class[]{String.class});
                newValue = MethodUtil.invoke(method, oldValue, new Object[] { editor.getText()});
            } catch (Exception ex) {
                // Fail silently and return the newValue (a String object)
            }
        }
    }
    return newValue;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:BasicComboBoxEditor.java

示例11: registerSimpleCommands

import java.lang.reflect.Method; //导入依赖的package包/类
@Override
public void registerSimpleCommands(Object object) {
    for (Method method : object.getClass().getDeclaredMethods()) {
        cn.nukkit.command.simple.Command def = method.getAnnotation(cn.nukkit.command.simple.Command.class);
        if (def != null) {
            SimpleCommand sc = new SimpleCommand(object, method, def.name(), def.description(), def.usageMessage(), def.aliases());

            Arguments args = method.getAnnotation(Arguments.class);
            if (args != null) {
                sc.setMaxArgs(args.max());
                sc.setMinArgs(args.min());
            }

            CommandPermission perm = method.getAnnotation(CommandPermission.class);
            if (perm != null) {
                sc.setPermission(perm.value());
            }

            if (method.isAnnotationPresent(ForbidConsole.class)) {
                sc.setForbidConsole(true);
            }

            this.register(def.name(), sc);
        }
    }
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:27,代码来源:SimpleCommandMap.java

示例12: maybeGetMethod

import java.lang.reflect.Method; //导入依赖的package包/类
private static Method maybeGetMethod(Class<?> clazz, String name, Class<?>... argClasses)
{
	try
	{
		return clazz.getMethod(name, argClasses);
	}
	catch (NoSuchMethodException nsme)
	{
		// OK
		return null;
	}
	catch (RuntimeException re)
	{
		Log.w(TAG, "Unexpected error while finding method " + name, re);
		return null;
	}
}
 
开发者ID:guzhigang001,项目名称:Zxing,代码行数:18,代码来源:FlashlightManager.java

示例13: getIDmethod

import java.lang.reflect.Method; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static Method getIDmethod(Class<? extends BaseDomain> clazz) {
	if (clazz.getAnnotation(IdClass.class) != null) {
		try {
			return clazz.getDeclaredMethod("getDomainID");
		} catch (NoSuchMethodException e) {
			throw new RuntimeException("含有"+IdClass.class.getName()+
					"的domain必须实现"+UnionKeyDomain.class.getName()+"接口!!!",e);
		}
	}
	
	Method[] methods = clazz.getDeclaredMethods();
	for (Method m:methods) {
		Annotation aa = m.getAnnotation(Id.class);
		if (aa == null) {
			continue;
		}
		return m;
	}
	if (clazz == BaseDomain.class) {
		return null;
	}
	return getIDmethod((Class<? extends BaseDomain>)clazz.getSuperclass());
}
 
开发者ID:battlesteed,项目名称:hibernateMaster,代码行数:25,代码来源:DomainUtil.java

示例14: invoke

import java.lang.reflect.Method; //导入依赖的package包/类
@Override
public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
    Sql sql = this.sql;

    if (method.getDeclaringClass() == SqlStreamHolder.class) {
        return sql;
    }

    TransactionStatus transactionStatus = null;
    try {
        transactionStatus = TransactionAspectSupport.currentTransactionStatus();
    } catch (NoTransactionException e) {
        if (FAIL_WITHOUT_TRANSACTION) {
            throw e;
        }
    }
    if (transactionStatus instanceof SqlStreamTransactionStatus) {
        sql = ((SqlStreamTransactionStatus) transactionStatus).transaction;
    }

    return method.invoke(sql, objects);
}
 
开发者ID:bendem,项目名称:sql-streams-spring,代码行数:23,代码来源:SqlStreamTransactionAwareProxy.java

示例15: invoke

import java.lang.reflect.Method; //导入依赖的package包/类
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    if (method.getName().equals("getStatement")) {
        return this.st;
    } else {
        try {
            return method.invoke(this.delegate, args);
        } catch (Throwable t) {
            if (t instanceof InvocationTargetException
                    && t.getCause() != null) {
                throw t.getCause();
            } else {
                throw t;
            }
        }
    }
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:18,代码来源:StatementDecoratorInterceptor.java


注:本文中的java.lang.reflect.Method类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。