vendredi 9 juin 2017

java reflection for hashmap

I couldn't find an example on the internet to use java reflection to create an hashmap and to set an hashamp. Here is the original java code I want to do it using java reflection:

    import java.util.HashMap;
    import java.util.Map;

    public class Test1 {

        Map systemParameters=null;

        public Map getSystemParameters() {
            return systemParameters;
        }

        public void setSystemParameters(Map systemParameters) {
            this.systemParameters = systemParameters;
        }

        public static void main(String[] args)
        {
            HashMap<String,String> map = new HashMap<String,String>();
            map.put("test1", "999");
            map.put("test2", "10");
            map.put("test3", "12");
            Test1 test1 = new Test1();
            test1.setSystemParameters(map);
        }
    }





Aucun commentaire:

Enregistrer un commentaire