提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
获取Java Bean属性类型
/** * Archivists' Toolkit(TM) Copyright ? 2005-2007 Regents of the University of California, New York University, & Five Colleges, Inc. * All rights reserved. * * This software is free. You can redistribute it and / or modify it under the terms of the Educational Community License (ECL) * version 1.0 (http://www.opensource.org/licenses/ecl1.php) * * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ECL license for more details about permissions and limitations. * * * Archivists' Toolkit(TM) * http://www.archiviststoolkit.org * info@archiviststoolkit.org * * @author Lee Mandell * Date: Mar 18, 2006 * Time: 5:34:03 PM */ //package com.nowjava; import java.beans.BeanInfo; import java.beans.Introspector; /** * 时代Java - N o w J a v a . c o m 提 供 **/ import java.beans.PropertyDescriptor; import java.beans.IntrospectionException; public class Main { public static void main(String[] argv) throws Exception { Class clazz = String.class; String propertyName = "nowjava.com"; System.out.println(getPropertyType(clazz, propertyName)); } public static Class getPropertyType(Class clazz, String propertyName) throws IntrospectionException { BeanInfo beanInfo = Introspector.getBeanInfo(clazz); PropertyDescriptor[] propertyDescriptors = beanInfo .getPropertyDescr