For beans that conform to the Java Bean specification, calling its methods should take precedence over method calls with Java.beans.PropertyDescriptor to obtain greater maintainability.
public void Gridcolumnfilter (list<?> List, map<string, object> DataMap) {for (iterator<?> Iterator = Li St.iterator (); Iterator.hasnext ();) {Object bean = Iterator.next (); for (int i = 0; i < indexs.length; i++) {//Use reflection class PropertyDescriptor PD = new property Descriptor (Indexs[i], Bean.getclass ()); Method getter = Pd.getreadmethod (); if (! String.valueof (Getter.invoke (Bean)). toLowerCase (). Contains (Values[i].tolowercase ())) {iterator.remove (); break;}}}
Through Class.forName or information of the kind
Public <T> list<t> Getresultlistfromcache (Object jsonobject,
Class<t> className) throws ClassNotFoundException {
list<t> list = new arraylist<t> ();
List = (list<t>) jsonarray.tocollection (
Jsonarray.fromobject (Jsonobject),
Class.forName (Classname.getname ()));
return list;
}
This article is from the "Jia Xiaoxian" blog, make sure to keep this source http://hackerxian.blog.51cto.com/9240575/1611816
Using PropertyDescriptor reflection on Java beans to call Java methods Low-coupling