本文整理匯總了Java中java.lang.reflect.Method.getParameterTypes方法的典型用法代碼示例。如果您正苦於以下問題:Java Method.getParameterTypes方法的具體用法?Java Method.getParameterTypes怎麽用?Java Method.getParameterTypes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.reflect.Method
的用法示例。
在下文中一共展示了Method.getParameterTypes方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getProperty
import java.lang.reflect.Method; //導入方法依賴的package包/類
public static Object getProperty(Object bean, String property)
throws IllegalArgumentException, IllegalAccessException,
InvocationTargetException, SecurityException, IntrospectionException,
NoSuchMethodException {
Object object = null;
Method getter = getReadMethod(bean.getClass(), property);
StringTokenizer st = new StringTokenizer(property, "[](,)", false);
capitalize(st.nextToken());
Object params[] = new Object[st.countTokens()];
for (int j = 0; j < params.length; j++) {
params[j] = st.nextToken();
if (getter.getParameterTypes()[0] == int.class) {
params[j] = new Integer((String) params[j]);
}
}
object = getter == null ? null : getter.invoke(bean, params);
return object;
}
示例2: getBeanValue
import java.lang.reflect.Method; //導入方法依賴的package包/類
/**
* 將ResultSet轉換為指定class的Bean.
* @param rs ResultSet實例
* @param rsmd ResultSet元數據
* @param beanClass 空屬性的Bean的class
* @param propMap Bean屬性對應的Map
* @param <T> 泛型方法
* @return 值
* @throws IllegalAccessException IllegalAccessException
* @throws SQLException SQLException
* @throws InvocationTargetException InvocationTargetException
* @throws InstantiationException InstantiationException
*/
public static <T> T getBeanValue(ResultSet rs, ResultSetMetaData rsmd, Class<T> beanClass,
Map<String, PropertyDescriptor> propMap) throws IllegalAccessException, SQLException,
InvocationTargetException, InstantiationException {
T bean = beanClass.newInstance();
for (int i = 0, cols = rsmd.getColumnCount(); i < cols; i++) {
String columnName = JdbcHelper.getColumn(rsmd, i + 1);
if (propMap.containsKey(columnName)) {
PropertyDescriptor prop = propMap.get(columnName);
// 獲取並調用setter方法.
Method propSetter = prop.getWriteMethod();
if (propSetter == null || propSetter.getParameterTypes().length != 1) {
log.warn("類'{}'的屬性'{}'沒有標準的setter方法", beanClass.getName(), columnName);
continue;
}
// 得到屬性類型並將該數據庫列值轉成Java對應類型的值
Class<?> propType = prop.getPropertyType();
Object value = FieldHandlerChain.newInstance().getColumnValue(rs, i + 1, propType);
propSetter.invoke(bean, value);
}
}
return bean;
}
示例3: LevelDListener
import java.lang.reflect.Method; //導入方法依賴的package包/類
public LevelDListener(Method method) {
NullCheck.check(method, "method");
this.method = method;
// check the annotation
if (getAnnotation() == null) {
throw new ListenerMethodParametersException(method, "There is no ObjectListener annotation on the method!", AnnotationListenerRegistrator.this);
}
// check the method signature
if (method.getParameterTypes().length != 1 ||
!method.getParameterTypes()[0].isAssignableFrom(IWorldObjectEvent.class)) {
throw new ListenerMethodParametersException(method, method.getAnnotation(ObjectListener.class), AnnotationListenerRegistrator.this);
}
objectId = getId(method, getAnnotation());
}
示例4: covertObjWithMap
import java.lang.reflect.Method; //導入方法依賴的package包/類
/**
* 根據傳遞的參數修改數據
*
* @param o
* @param parameterMap map參數
*/
public static final void covertObjWithMap(Object o, Map<String, String> parameterMap) {
Class<?> clazz = o.getClass();
Iterator<Map.Entry<String, String>> iterator = parameterMap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, String> entry = iterator.next();
String key = entry.getKey().trim();
String value = entry.getValue().trim();
try {
Method method = setMethod(key, clazz);
if (method != null) {
Class<?>[] parameterTypes = method.getParameterTypes();
if (method != null) {
Object[] param_value = new Object[] { TypeParseUtil.convert(value, parameterTypes[0], null) };
method.invoke(o, param_value);
}
}
} catch (Exception e) {
logger.error("", e);
}
}
}
示例5: findMethod
import java.lang.reflect.Method; //導入方法依賴的package包/類
private static Method findMethod(Class service, String methodName, Object[] args) {
Method[] methods = service.getMethods();
Method invokeMethod = null;
for (Method m : methods) {
if (m.getName().equals(methodName) && m.getParameterTypes().length == args.length) {
if (invokeMethod != null) { // 重載
if (isMatch(invokeMethod.getParameterTypes(), args)) {
invokeMethod = m;
break;
}
} else {
invokeMethod = m;
}
}
}
return invokeMethod;
}
示例6: getReadResolve
import java.lang.reflect.Method; //導入方法依賴的package包/類
/**
* Returns the readResolve method
*/
protected Method getReadResolve(Class cl)
{
for (; cl != null; cl = cl.getSuperclass()) {
Method []methods = cl.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
if (method.getName().equals("readResolve") &&
method.getParameterTypes().length == 0)
return method;
}
}
return null;
}
示例7: getAllMethod
import java.lang.reflect.Method; //導入方法依賴的package包/類
/**
* 獲取api類中所有符合要求的api方法並緩存
*
* @param injectedCls
* @return
* @throws Exception
*/
private static HashMap<String, Method> getAllMethod(Class injectedCls) throws Exception {
HashMap<String, Method> mMethodsMap = new HashMap<>();
Method[] methods = injectedCls.getDeclaredMethods();
for (Method method : methods) {
String name;
if (method.getModifiers() != (Modifier.PUBLIC | Modifier.STATIC) || (name = method.getName()) == null) {
continue;
}
Class[] parameters = method.getParameterTypes();
if (null != parameters && parameters.length == 4) {
if (parameters[1] == WebView.class && parameters[2] == JSONObject.class && parameters[3] == Callback.class) {
mMethodsMap.put(name, method);
}
}
}
return mMethodsMap;
}
示例8: Invocation
import java.lang.reflect.Method; //導入方法依賴的package包/類
public Invocation(Method method, Object[] parameters) {
this.methodName = method.getName();
this.parameterClasses = method.getParameterTypes();
this.parameters = parameters;
rpcVersion = writableRpcVersion;
if (method.getDeclaringClass().equals(VersionedProtocol.class)) {
//VersionedProtocol is exempted from version check.
clientVersion = 0;
clientMethodsHash = 0;
} else {
this.clientVersion = RPC.getProtocolVersion(method.getDeclaringClass());
this.clientMethodsHash = ProtocolSignature.getFingerprint(method
.getDeclaringClass().getMethods());
}
this.declaringClassProtocolName =
RPC.getProtocolName(method.getDeclaringClass());
}
示例9: checkCompatibility
import java.lang.reflect.Method; //導入方法依賴的package包/類
private void checkCompatibility(Event event1, Event event2) {
Method m1 = event1.getListenerMethod();
Method m2 = event2.getListenerMethod();
Class[] params1 = m1.getParameterTypes();
Class[] params2 = m2.getParameterTypes();
boolean ok;
if (params1.length == params2.length) {
ok = true;
for (int i=0; i < params1.length; i++)
if (!params1[i].getName().equals(params2[i].getName())) {
ok = false;
break;
}
if (ok)
ok = m1.getReturnType().equals(m2.getReturnType());
}
else ok = false;
if (!ok) {
IllegalArgumentException iae =
new IllegalArgumentException("Incompatible event"); // NOI18N
org.openide.ErrorManager.getDefault().annotate(
iae, FormUtils.getBundleString("MSG_CannotAttach")); // NOI18N
throw iae;
}
}
示例10: setProperty
import java.lang.reflect.Method; //導入方法依賴的package包/類
public static boolean setProperty(Object target, String name, Object value) {
try {
Class<?> clazz = target.getClass();
if (target instanceof SSLServerSocket) {
// overcome illegal access issues with internal implementation class
clazz = SSLServerSocket.class;
}
Method setter = findSetterMethod(clazz, name);
if (setter == null) {
return false;
}
// If the type is null or it matches the needed type, just use the
// value directly
if (value == null || value.getClass() == setter.getParameterTypes()[0]) {
setter.invoke(target, value);
} else {
// We need to convert it
setter.invoke(target, convert(value, setter.getParameterTypes()[0]));
}
return true;
} catch (Exception e) {
LOG.error(String.format("Could not set property %s on %s", name, target), e);
return false;
}
}
示例11: invokePublicInstanceMethodWithDefaultValues
import java.lang.reflect.Method; //導入方法依賴的package包/類
private static void invokePublicInstanceMethodWithDefaultValues(Object instance, Method method)
throws InvocationTargetException, IllegalAccessException {
List<Object> parameters = new ArrayList<>(method.getParameterTypes().length);
for (Class<?> parameterType : method.getParameterTypes()) {
parameters.add(Defaults.defaultValue(parameterType));
}
method.invoke(instance, parameters.toArray());
}
示例12: Record
import java.lang.reflect.Method; //導入方法依賴的package包/類
private Record(Object target, Method method) {
this.target = target;
this.method = method;
final TypeToken<?> returnType;
if(Optional.class.isAssignableFrom(method.getReturnType())) {
optional = true;
returnType = Optionals.elementType(method.getGenericReturnType());
} else {
optional = false;
returnType = TypeToken.of(method.getGenericReturnType());
}
if(!type.isAssignableFrom(returnType)) {
throw new IllegalStateException("Method " + method + " return type " + returnType + " is not assignable to " + type);
}
if(method.getParameterTypes().length == 0) {
passElement = false;
} else {
if(!(method.getParameterTypes().length == 1 && Element.class.isAssignableFrom(method.getParameterTypes()[0]))) {
throw new IllegalStateException("Method " + method + " should take no parameters, or a single Element parameter");
}
passElement = true;
}
try {
this.handle = MethodHandleUtils.privateLookup(method.getDeclaringClass())
.unreflect(method)
.bindTo(target);
} catch(IllegalAccessException e) {
throw Throwables.propagate(e);
}
}
示例13: getNamedParameters
import java.lang.reflect.Method; //導入方法依賴的package包/類
public LinkedHashSet<NamedParameter> getNamedParameters(String resource, boolean excludeOverriden) throws Exception {
LinkedHashMap<String, NamedParameter> namedParameters = new LinkedHashMap<String, NamedParameter>();
Method method = getAnnotatedMethod(resource);
if (method != null) {
MethodParameterNames annotation = method.getAnnotation(MethodParameterNames.class);
String[] parameterNames = null;
if (annotation != null) {
parameterNames = annotation.value();
}
Class[] parameterTypes = method.getParameterTypes();
if (parameterNames != null && parameterTypes != null) {
for (int i = 0; i < parameterNames.length; i++) {
namedParameters.put(parameterNames[i], new NamedParameter(parameterNames[i], parameterTypes[i]));
}
}
}
Iterator<Entry<String, Object>> it = defaults.entrySet().iterator();
while (it.hasNext()) {
Entry<String, Object> defaultParameter = it.next();
if (!namedParameters.containsKey(defaultParameter.getKey())) {
namedParameters.put(defaultParameter.getKey(), new NamedParameter(defaultParameter.getKey(), defaultParameter.getValue().getClass()));
}
}
it = overrides.entrySet().iterator();
while (it.hasNext()) {
Entry<String, Object> overrideParameter = it.next();
namedParameters.put(overrideParameter.getKey(), new NamedParameter(overrideParameter.getKey(), overrideParameter.getValue().getClass()));
}
if (excludeOverriden) {
it = overrides.entrySet().iterator();
while (it.hasNext()) {
namedParameters.remove(it.next().getKey());
}
}
return new LinkedHashSet<NamedParameter>(namedParameters.values());
}
示例14: GenericTypeAwarePropertyDescriptor
import java.lang.reflect.Method; //導入方法依賴的package包/類
public GenericTypeAwarePropertyDescriptor(Class<?> beanClass, String propertyName,
Method readMethod, Method writeMethod, Class<?> propertyEditorClass)
throws IntrospectionException {
super(propertyName, null, null);
this.beanClass = beanClass;
this.propertyEditorClass = propertyEditorClass;
Method readMethodToUse = BridgeMethodResolver.findBridgedMethod(readMethod);
Method writeMethodToUse = BridgeMethodResolver.findBridgedMethod(writeMethod);
if (writeMethodToUse == null && readMethodToUse != null) {
// Fallback: Original JavaBeans introspection might not have found matching setter
// method due to lack of bridge method resolution, in case of the getter using a
// covariant return type whereas the setter is defined for the concrete property type.
Method candidate = ClassUtils.getMethodIfAvailable(
this.beanClass, "set" + StringUtils.capitalize(getName()), (Class<?>[]) null);
if (candidate != null && candidate.getParameterTypes().length == 1) {
writeMethodToUse = candidate;
}
}
this.readMethod = readMethodToUse;
this.writeMethod = writeMethodToUse;
if (this.writeMethod != null && this.readMethod == null) {
// Write method not matched against read method: potentially ambiguous through
// several overloaded variants, in which case an arbitrary winner has been chosen
// by the JDK's JavaBeans Introspector...
Set<Method> ambiguousCandidates = new HashSet<Method>();
for (Method method : beanClass.getMethods()) {
if (method.getName().equals(writeMethodToUse.getName()) &&
!method.equals(writeMethodToUse) && !method.isBridge()) {
ambiguousCandidates.add(method);
}
}
if (!ambiguousCandidates.isEmpty()) {
this.ambiguousWriteMethods = ambiguousCandidates;
}
}
}
示例15: invoke
import java.lang.reflect.Method; //導入方法依賴的package包/類
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
final Myth myth = method.getAnnotation(Myth.class);
final Class<?>[] arguments = method.getParameterTypes();
final Class clazz = method.getDeclaringClass();
if (Objects.nonNull(myth)) {
final MythTransactionContext mythTransactionContext =
TransactionContextLocal.getInstance().get();
try {
final MythParticipant participant =
buildParticipant(mythTransactionContext, myth,
method, clazz, args, arguments);
if (Objects.nonNull(participant)) {
final MythTransactionManager mythTransactionManager =
SpringBeanUtils.getInstance().getBean(MythTransactionManager.class);
mythTransactionManager.registerParticipant(participant);
}
return super.invoke(target, method, args);
} catch (Throwable throwable) {
throwable.printStackTrace();
return getDefaultValue(method.getReturnType());
}
} else {
return super.invoke(target, method, args);
}
}