java getparametertypes_Java Method.getParameterTypes方法代碼示例

本文详细整理了Java中Method.getParameterTypes方法的多种应用场景和代码示例,包括getProperty、getBeanValue、LevelDListener等场景。通过这些示例,你可以了解如何在实际项目中使用该方法获取方法参数类型。
摘要由CSDN通过智能技术生成

本文整理匯總了Java中java.lang.reflect.Method.getParameterTypes方法的典型用法代碼示例。如果您正苦於以下問題:Java Method.getParameterTypes方法的具體用法?Java Method.getParameterTypes怎麽用?Java Method.getParameterTypes使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.reflect.Method的用法示例。

在下文中一共展示了Method.getParameterTypes方法的19個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。

示例1: getProperty

​點讚 4

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;

}

開發者ID:dvbern,項目名稱:doctemplate,代碼行數:19,

示例2: getBeanValue

​點讚 3

import java.lang.reflect.Method; //導入方法依賴的package包/類

/**

* 將ResultSet轉換為指定class的Bean.

* @param rs ResultSet實例

* @param rsmd ResultSet元數據

* @param beanClass 空屬性的Bean的class

* @param propMap Bean屬性對應的Map

* @param 泛型方法

* @return 值

* @throws IllegalAccessException IllegalAccessException

* @throws SQLException SQLException

* @throws InvocationTargetException InvocationTargetException

* @throws InstantiationException InstantiationException

*/

public static T getBeanValue(ResultSet rs, ResultSetMetaData rsmd, Class beanClass,

Map 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;

}

開發者ID:blinkfox,項目名稱:adept,代碼行數:37,

示例3: LevelDListener

​點讚 3

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());

}

開發者ID:kefik,項目名稱:Pogamut3,代碼行數:18,

示例4: covertObjWithMap

​點讚 3

import java.lang.reflect.Method; //導入方法依賴的package包/類

/**

* 根據傳遞的參數修改數據

*

* @param o

* @param parameterMap map參數

*/

public static final void covertObjWithMap(Object o, Map parameterMap) {

Class> clazz = o.getClass();

Iterator> iterator = parameterMap.entrySet().iterator();

while (iterator.hasNext()) {

Map.Entry entry = iterator.next();

String key = entry.getKey().trim();<

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值