本文整理了Java中java.lang.reflect.Method.getReturnType()
方法的一些代码示例,展示了Method.getReturnType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Method.getReturnType()
方法的具体详情如下:
包路径:java.lang.reflect.Method
类名称:Method
方法名:getReturnType
[英]Returns a Class object that represents the formal return type of the method represented by this Method object.
[中]返回一个类对象,该类对象表示此方法对象表示的方法的形式返回类型。
代码示例来源:origin: spring-projects/spring-framework
/**
* Determine if the supplied {@code method} is an annotation attribute method.
* @param method the method to check
* @return {@code true} if the method is an attribute method
* @since 4.2
*/
static boolean isAttributeMethod(@Nullable Method method) {
return (method != null && method.getParameterCount() == 0 && method.getReturnType() != void.class);
}
代码示例来源:origin: spring-projects/spring-framework
@Nullable
private Object wrapCacheValue(Method method, @Nullable Object cacheValue) {
if (method.getReturnType() == Optional.class &&
(cacheValue == null || cacheValue.getClass() != Optional.class)) {
return Optional.ofNullable(cacheValue);
}
return cacheValue;
}
代码示例来源:origin: spring-projects/spring-framework
public static boolean isCandidateWriteMethod(Method method) {
String methodName = method.getName();
Class<?>[] parameterTypes = method.getParameterTypes();
int nParams = parameterTypes.length;
return (methodName.length() > 3 && methodName.startsWith("set") && Modifier.isPublic(method.getModifiers()) &&
(!void.class.isAssignableFrom(method.getReturnType()) || Modifier.isStatic(method.getModifiers())) &&
(nParams == 1 || (nParams == 2 && int.class == parameterTypes[0])));
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Determine the conventional variable name for the return type of the given
* method, taking the generic collection type, if any, into account, falling
* back on the given actual return value if the method declaration is not
* specific enough, e.g. {@code Object} return type or untyped collection.
* @param method the method to generate a variable name for
* @param value the return value (may be {@code null} if not available)
* @return the generated variable name
*/
public static String getVariableNameForReturnType(Method method, @Nullable Object value) {
return getVariableNameForReturnType(method, method.getReturnType(), value);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Determine the conventional variable name for the return type of the
* given method, taking the generic collection type, if any, into account.
* @param method the method to generate a variable name for
* @return the generated variable name
*/
public static String getVariableNameForReturnType(Method method) {
return getVariableNameForReturnType(method, method.getReturnType(), null);
}
代码示例来源:origin: spring-projects/spring-framework
@Nullable
private static Method determineToMethod(Class<?> targetClass, Class<?> sourceClass) {
if (String.class == targetClass || String.class == sourceClass) {
// Do not accept a toString() method or any to methods on String itself
return null;
}
Method method = ClassUtils.getMethodIfAvailable(sourceClass, "to" + targetClass.getSimpleName());
return (method != null && !Modifier.isStatic(method.getModifiers()) &&
ClassUtils.isAssignable(targetClass, method.getReturnType()) ? method : null);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public boolean matches(Method method, Class<?> targetClass) {
return method.getReturnType().equals(String.class);
}
},
代码示例来源:origin: spring-projects/spring-framework
@Override
public boolean matches(Method m, @Nullable Class<?> targetClass) {
return m.getReturnType() == int.class;
}
};
代码示例来源:origin: spring-projects/spring-framework
@Override
public boolean matches(Method m, @Nullable Class<?> targetClass, Object... args) {
return m.getReturnType() == Void.TYPE;
}
});
代码示例来源:origin: google/guava
InteractionTester(Class<T> interfaceType, Method method) {
this.interfaceType = interfaceType;
this.method = method;
this.passedArgs = getParameterValues(method);
this.returnValue = new FreshValueGenerator().generateFresh(method.getReturnType());
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Return the type of object that this FactoryBean creates,
* or {@code null} if not known in advance.
*/
@Override
public Class<?> getObjectType() {
if (!isPrepared()) {
// Not fully initialized yet -> return null to indicate "not known yet".
return null;
}
return getPreparedMethod().getReturnType();
}
代码示例来源:origin: spring-projects/spring-framework
private static Method findMethodWithReturnType(String name, Class<?> returnType, Class<SettingsDaoImpl> targetType) {
Method[] methods = targetType.getMethods();
for (Method m : methods) {
if (m.getName().equals(name) && m.getReturnType().equals(returnType)) {
return m;
}
}
return null;
}
代码示例来源:origin: spring-projects/spring-framework
private static Method getMethodForReturnType(Class<?> returnType) {
return Arrays.stream(TestBean.class.getMethods())
.filter(method -> method.getReturnType().equals(returnType))
.findFirst()
.orElseThrow(() ->
new IllegalArgumentException("Unique return type not found: " + returnType));
}
代码示例来源:origin: google/guava
static void verifyConsitentRawType() {
for (Method method : RawTypeConsistencyTester.class.getDeclaredMethods()) {
assertEquals(
method.getReturnType(), TypeToken.of(method.getGenericReturnType()).getRawType());
for (int i = 0; i < method.getParameterTypes().length; i++) {
assertEquals(
method.getParameterTypes()[i],
TypeToken.of(method.getGenericParameterTypes()[i]).getRawType());
}
}
}
}
代码示例来源:origin: google/guava
@GwtIncompatible // reflection
public void testAsMapBridgeMethods() {
for (Method m : TreeMultimap.class.getMethods()) {
if (m.getName().equals("asMap") && m.getReturnType().equals(SortedMap.class)) {
return;
}
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
assertTrue(!Thread.currentThread().getName().equals(originalThreadName));
if (Future.class.equals(invocation.getMethod().getReturnType())) {
return new AsyncResult<>(invocation.getArguments()[0].toString());
}
return null;
}
});
代码示例来源:origin: spring-projects/spring-framework
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
assertTrue(!Thread.currentThread().getName().equals(originalThreadName));
if (Future.class.equals(invocation.getMethod().getReturnType())) {
return new AsyncResult<>(invocation.getArguments()[0].toString());
}
return null;
}
});
代码示例来源:origin: google/guava
@GwtIncompatible // reflection
public void testKeySetBridgeMethods() {
for (Method m : TreeMultimap.class.getMethods()) {
if (m.getName().equals("keySet") && m.getReturnType().equals(SortedSet.class)) {
return;
}
}
fail("No bridge method found");
}
代码示例来源:origin: google/guava
@GwtIncompatible // reflection
public void testGetBridgeMethods() {
for (Method m : TreeMultimap.class.getMethods()) {
if (m.getName().equals("get") && m.getReturnType().equals(SortedSet.class)) {
return;
}
}
fail("No bridge method found");
}
}
代码示例来源:origin: google/guava
@GwtIncompatible // reflection
@AndroidIncompatible // Reflection bug, or actual binary compatibility problem?
public void testElementSetBridgeMethods() {
for (Method m : TreeMultiset.class.getMethods()) {
if (m.getName().equals("elementSet") && m.getReturnType().equals(SortedSet.class)) {
return;
}
}
fail("No bridge method found");
}
}
内容来源于网络,如有侵权,请联系作者删除!