Property set and get values for dynamically assigned Java classes

Source: Internet
Author: User

public class Contact {private String Name;private string tel;private attrcontrol attrc=new attrcontrol ();p rivate class att Rcontrol{public map<string,object> map=new HashMap ();p ublic Object isexist;public Map createattr (String a,String Value) {Object Obj= (object) Value;isexist=map.get (a); if (isexist==null) {map.put (a,obj);} Map.put (a,obj); return map;}} public void Setobj (String newattr,string value) {attrc.createattr (newattr,value);} Public Object getobj (String newattr) {Map a=attrc.map; return A.get (newattr);} public static void Main (string[] args) {Contact a =new contact () a.setobj ("Mail", "[e-mail protected]") a.setobj ("area", " 882 "); System.out.println ("Mail:" +string.valueof (A.getobj ("Mail")); System.out.println ("Area:" +integer.parseint (A.getobj ("area"). ToString ()));}}

At this point, you can dynamically put the property, and the value. It is just not permanent to save the attribute information, there is the word of the great God, can comment under.

Property set and get values for dynamically assigned Java classes

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.