vendredi 5 juin 2020

use reflection to set or get array in a Java Map

Is there a way to get or set an array element stored in a Java Map?

Example:

If we have a map like this:

{
   name: "Blah",
   friends: ["Foo", "Bar"]
}

Map<String, Object> myMap = new HashMap<>();
List<String> friends = new ArrayList<>();
myMap.put("name", "Blah");
myMap.put("friends", friends);

Is it possible to use Reflection to get or set the first element in the friends array in the "myMap" from the string: "myMap.friends[0]"





Aucun commentaire:

Enregistrer un commentaire