Using PropertyDescriptor reflection on Java beans to call Java methods Low-coupling

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.