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


Java Method.getReturnType方法代码示例

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


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

示例1: callMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
public Reflections callMethod(String methodName, MethodCallback callback, Object ... params) {
	try {
		Class[] parameterTypes = types(params);
		Method method = getMethod(methodName,parameterTypes);
		method.setAccessible(true);
		if(method.getReturnType() == void.class){
			method.invoke(object, params);
		}else{
			Object returnValue = method.invoke(object, params);
			if(callback != null) callback.done(returnValue);
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return this;
}
 
开发者ID:coding-dream,项目名称:Notebook,代码行数:17,代码来源:Reflections.java

示例2: invoke

import java.lang.reflect.Method; //导入方法依赖的package包/类
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    try {
        Object ret = method.invoke(orig, args);
        Class<?> returnType = method.getReturnType();
        if (WRAP_TARGET_CLASSES.contains(returnType)) {
            ret = Proxy.newProxyInstance(returnType.getClassLoader(), new Class[]{returnType},
                    new GokuInvocationHandler(ret));
        }
        return ret;
    } catch (InvocationTargetException ex) {
        Throwable targetEx = ex.getTargetException();
        if (targetEx instanceof SQLException) {
            targetEx = new GokuSQLException((SQLException) targetEx);
        }
        throw targetEx;
    }
}
 
开发者ID:kawasima,项目名称:goku-jdbc,代码行数:19,代码来源:GokuInvocationHandler.java

示例3: generatedClassesInCorrectPackageForFilesFirstSort

import java.lang.reflect.Method; //导入方法依赖的package包/类
@Test
@SuppressWarnings({"rawtypes", "unchecked"})
public void generatedClassesInCorrectPackageForFilesFirstSort() throws ClassNotFoundException, SecurityException,
        NoSuchMethodException {

    ClassLoader resultsClassLoader = schemaRule.generateAndCompile(
            "/schema/sourceSortOrder/", "com.example", config("sourceSortOrder", SourceSortOrder.FILES_FIRST
                    .toString()));

    Class generatedTypeA = resultsClassLoader.loadClass("com.example.A");
    Class generatedTypeZ = resultsClassLoader.loadClass("com.example.Z");

    Method getterTypeA = generatedTypeA.getMethod("getRefToA");
    final Class<?> returnTypeA = getterTypeA.getReturnType();

    Method getterTypeZ = generatedTypeZ.getMethod("getRefToZ");
    final Class<?> returnTypeZ = getterTypeZ.getReturnType();

    assertInPackage("com.example", generatedTypeA);
    assertInPackage("com.example", generatedTypeZ);
    assertInPackage("com.example", returnTypeA);
    assertInPackage("com.example", returnTypeZ);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:SourceSortOrderIT.java

示例4: checkViewOnShowOrLeaveMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * Check given method has a valid signature for {@link OnShow} or {@link OnLeave} view method
 * @param viewClass View class
 * @param method Method to check
 * @param message Error message annotation description
 * @throws ViewConfigurationException Method is not valid
 */
private static void checkViewOnShowOrLeaveMethod(Class<?> viewClass, Method method, String message)
		throws ViewConfigurationException {
	if (method.getReturnType() != Void.class && method.getReturnType() != Void.TYPE) {
		throw new ViewConfigurationException("Invalid " + message + " method in view class " + viewClass.getName()
				+ ": method must be a void return method");
	}
	int params = method.getParameterCount();
	if (params > 1) {
		throw new ViewConfigurationException("Invalid " + message + " method in view class " + viewClass.getName()
				+ ": method must have no parameters or only one parameter of type ViewChangeEvent");
	}
	if (params == 1) {
		Parameter param = method.getParameters()[0];
		if (param.isVarArgs() || !(ViewChangeEvent.class.isAssignableFrom(param.getType())
				|| ViewNavigatorChangeEvent.class.isAssignableFrom(param.getType()))) {
			throw new ViewConfigurationException(
					"Invalid " + message + " method in view class " + viewClass.getName()
							+ ": method must have no parameters or only one parameter of type ViewChangeEvent");
		}
	}
}
 
开发者ID:holon-platform,项目名称:holon-vaadin,代码行数:29,代码来源:ViewNavigationUtils.java

示例5: parseTargetMapping

import java.lang.reflect.Method; //导入方法依赖的package包/类
private static FlowExecutor.TargetMappingExecutor parseTargetMapping(Method method) {
    logger.debug("解析目标对象映射方法:{}", method);
    // 校验方法类型
    if (!Modifier.isPublic(method.getModifiers())) {
        throw new IllegalArgumentException("目标对象映射方法" + ClassUtils.getQualifiedMethodName(method) + "必须是public类型");
    }
    // 校验入参
    Class[] parameterTypes = method.getParameterTypes();
    if (parameterTypes.length != 1) {
        throw new IllegalArgumentException("目标对象映射方法" + ClassUtils.getQualifiedMethodName(method) + "必须只能有一个入参");
    }
    // 校验返回参数
    if (method.getReturnType() != String.class) {
        throw new IllegalArgumentException("目标对象映射方法" + ClassUtils.getQualifiedMethodName(method) + "返回参数必须是String类型");
    }

    return new FlowExecutor.TargetMappingExecutor(method, parameterTypes[0]);
}
 
开发者ID:zhongxunking,项目名称:bekit,代码行数:19,代码来源:FlowParser.java

示例6: validateMainClass

import java.lang.reflect.Method; //导入方法依赖的package包/类
static void validateMainClass(Class<?> mainClass) {
    Method mainMethod;
    try {
        mainMethod = mainClass.getMethod("main", String[].class);
    } catch (NoSuchMethodException nsme) {
        // invalid main or not FX application, abort with an error
        abort(null, "java.launcher.cls.error4", mainClass.getName(),
              FXHelper.JAVAFX_APPLICATION_CLASS_NAME);
        return; // Avoid compiler issues
    }

    /*
     * getMethod (above) will choose the correct method, based
     * on its name and parameter type, however, we still have to
     * ensure that the method is static and returns a void.
     */
    int mod = mainMethod.getModifiers();
    if (!Modifier.isStatic(mod)) {
        abort(null, "java.launcher.cls.error2", "static",
              mainMethod.getDeclaringClass().getName());
    }
    if (mainMethod.getReturnType() != java.lang.Void.TYPE) {
        abort(null, "java.launcher.cls.error3",
              mainMethod.getDeclaringClass().getName());
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:LauncherHelper.java

示例7: getPrivateMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * Returns non-static private method with given signature defined by given
 * class, or null if none found.  Access checks are disabled on the
 * returned method (if any).
 */
private static Method getPrivateMethod(Class<?> cl, String name,
                                       Class<?>[] argTypes,
                                       Class<?> returnType)
{
    try {
        Method meth = cl.getDeclaredMethod(name, argTypes);
        meth.setAccessible(true);
        int mods = meth.getModifiers();
        return ((meth.getReturnType() == returnType) &&
                ((mods & Modifier.STATIC) == 0) &&
                ((mods & Modifier.PRIVATE) != 0)) ? meth : null;
    } catch (NoSuchMethodException ex) {
        return null;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:ObjectStreamClass.java

示例8: register

import java.lang.reflect.Method; //导入方法依赖的package包/类
public void register(Object obj) {
	for (Method m : obj.getClass().getMethods()) {
		if (!Modifier.isStatic(m.getModifiers()) && m.getParameterCount() == 1
				&& m.getParameterTypes()[0] == CommandContext.class) {
			if (m.isAnnotationPresent(Command.class) && m.getReturnType() == boolean.class) {
				registerCommand(m, obj);
			} else if (m.isAnnotationPresent(Completer.class) && m.getReturnType() == List.class) {
				registerCompleter(m, obj);
			}
		}
	}
}
 
开发者ID:mcardy,项目名称:MystiCraft,代码行数:13,代码来源:CommandManager.java

示例9: invoke

import java.lang.reflect.Method; //导入方法依赖的package包/类
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    String methodName = method.getName();
    Class[] paramTypes = method.getParameterTypes();

    if ("hashCode".equals(methodName)) {
        return new Integer(System.identityHashCode(proxy));
    } else if ("equals".equals(methodName) && paramTypes.length == 1 && paramTypes[0] == Object.class) {
        return Boolean.valueOf(args[0] == proxy);
    }
        
    Class retClass = method.getReturnType();
    
    if (retClass.isPrimitive()) {
        if (retClass == Byte.TYPE) {
            return new Byte((byte)0);
        } else if (retClass == Short.TYPE) {
            return new Short((short)0);
        } else if (retClass == Integer.TYPE) {
            return new Integer(0);
        } else if (retClass == Long.TYPE) {
            return new Long(0L);
        } else if (retClass == Float.TYPE) {
            return new Float(0);
        } else if (retClass == Double.TYPE) {
            return new Double(0.0);
        } else if (retClass == Character.TYPE) {
            return new Character('\0');
        } else if (retClass == Boolean.TYPE) {
            return Boolean.FALSE;
        }
    }
        
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:Stub.java

示例10: typeExtendsJavaClassWithGenerics

import java.lang.reflect.Method; //导入方法依赖的package包/类
@Test
public void typeExtendsJavaClassWithGenerics() throws NoSuchMethodException {
    Method getterMethod = classWithManyTypes.getMethod("getTypeWithInheritedClassWithGenerics");

    final Class<?> generatedClass = getterMethod.getReturnType();
    assertThat(generatedClass.getName(), is("com.example.TypeWithInheritedClassWithGenerics"));
    assertThat(generatedClass.getSuperclass().equals(InheritedClassWithGenerics.class), equalTo(true));
    assertThat(((ParameterizedType) generatedClass.getGenericSuperclass()).getActualTypeArguments(), equalTo(new Type[]
            {
                    String.class, Integer.class, Boolean.class
            }));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:TypeIT.java

示例11: MemberType

import java.lang.reflect.Method; //导入方法依赖的package包/类
public MemberType(Method method, Type clazzType) {
    this.clazz = method.getReturnType();
    this.clazzType = clazzType;

    if(clazz.isArray()) {
        component = clazz.getComponentType();
    } else {
        component = (Class<?>)((ParameterizedType)method.getGenericReturnType()).getActualTypeArguments()[0];
    }
}
 
开发者ID:Guichaguri,项目名称:FastMustache,代码行数:11,代码来源:MemberType.java

示例12: isOverridableObjectMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
private static boolean isOverridableObjectMethod(final Method m) {
    switch (m.getName()) {
        case "equals":
            if (m.getReturnType() == boolean.class) {
                final Class<?>[] params = m.getParameterTypes();
                return params.length == 1 && params[0] == Object.class;
            }
            return false;
        case "hashCode":
            return m.getReturnType() == int.class && m.getParameterCount() == 0;
        case "toString":
            return m.getReturnType() == String.class && m.getParameterCount() == 0;
    }
    return false;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:NashornBeansLinker.java

示例13: MemberName

import java.lang.reflect.Method; //导入方法依赖的package包/类
@SuppressWarnings("LeakingThisInConstructor")
public MemberName(Method m, boolean wantSpecial) {
    m.getClass();  // NPE check
    // fill in vmtarget, vmindex while we have m in hand:
    MethodHandleNatives.init(this, m);
    if (clazz == null) {  // MHN.init failed
        if (m.getDeclaringClass() == MethodHandle.class &&
            isMethodHandleInvokeName(m.getName())) {
            // The JVM did not reify this signature-polymorphic instance.
            // Need a special case here.
            // See comments on MethodHandleNatives.linkMethod.
            MethodType type = MethodType.methodType(m.getReturnType(), m.getParameterTypes());
            int flags = flagsMods(IS_METHOD, m.getModifiers(), REF_invokeVirtual);
            init(MethodHandle.class, m.getName(), type, flags);
            if (isMethodHandleInvoke())
                return;
        }
        throw new LinkageError(m.toString());
    }
    assert(isResolved() && this.clazz != null);
    this.name = m.getName();
    if (this.type == null)
        this.type = new Object[] { m.getReturnType(), m.getParameterTypes() };
    if (wantSpecial) {
        if (isAbstract())
            throw new AbstractMethodError(this.toString());
        if (getReferenceKind() == REF_invokeVirtual)
            changeReferenceKind(REF_invokeSpecial, REF_invokeVirtual);
        else if (getReferenceKind() == REF_invokeInterface)
            // invokeSpecial on a default method
            changeReferenceKind(REF_invokeSpecial, REF_invokeInterface);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:34,代码来源:MemberName.java

示例14: getReturnClassImports

import java.lang.reflect.Method; //导入方法依赖的package包/类
private String getReturnClassImports(
                                      Class<?> actionClass ) {

    Method[] actionClassMethods = actionClass.getDeclaredMethods();
    //using TreeSet to prevent duplication of imports and have sorted list
    Set<String> imports = new TreeSet<String>();
    for (Method m : actionClassMethods) {
        if (ActionClassGenerator.isAnActionClass(m)) {

            // import method return type if needed
            Class<?> returnType = m.getReturnType();
            //check if the return type is an array
            if (returnType.getComponentType() != null) {
                returnType = returnType.getComponentType();
            }
            if (needsToImportMethodReturnType(returnType)) {
                addImport(imports, returnType, m.getGenericReturnType());
            }

            // import method parameter types if needed
            Class<?> methodParameterTypes[] = m.getParameterTypes();
            Type methodGenericParameterTypes[] = m.getGenericParameterTypes();
            for (int i = 0; i < methodParameterTypes.length; i++) {
                Class<?> methodParameterType = methodParameterTypes[i];
                if (needsToImportMethodParameterType(methodParameterType)) {
                    addImport(imports, methodParameterType, methodGenericParameterTypes[i]);
                }
            }
        }
    }
    if (imports.size() > 0) {
        StringBuilder sb = new StringBuilder();
        for (String s : imports) {
            sb.append(s);
        }
        return sb.toString();
    } else {
        return "";
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:41,代码来源:ClassTemplateProcessor.java

示例15: getUnmarshaller

import java.lang.reflect.Method; //导入方法依赖的package包/类
@Override
public ArgumentUnmarshaller getUnmarshaller(
        Method getter,
        Method setter) {
    final StandardAnnotationMaps.FieldMap<?> annotations = StandardAnnotationMaps.of(getter, null);
    final DynamoDbMarshalling marshalling = annotations.actualOf(DynamoDbMarshalling.class);
    if (marshalling != null) {
        return new CustomUnmarshaller(getter.getReturnType(), marshalling.marshallerClass());
    }
    return wrapped.getUnmarshaller(getter, setter);
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:12,代码来源:ConversionSchemas.java


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