Although unconventional, it is possible to create a <Object,Object>
map in JavaScript due to its flexibility with mixed datatypes.
One approach could be converting boolean values to strings for consistency within the "raw object map."
Map<Object, Object> test = new HashMap<>();
test.put("firstString", "first");
test.put("secondString", "second");
test.put("thirdBool", true);
In regards to the provided code:
Map<Object, Object> test = new HashMap<>();
test.put("value", "value");
test.put("label", "label");
test.put("disabled", false);
For custom classes, it's recommended to define a specific class structure like this:
class FooObject{
private String value;
private String label;
private boolean disabled;
FooObject(String value,String label,boolean disabled){
this.value=value;
this.label=label;
this.disabled=disabled;
}
public String getValue(){
return this.value;
}
public String getLabel(){
return this.label;
}
public boolean isDisabled(){
return this.disabled;
}
}
This custom class can then be used in a map as shown below:
Map<Integer, FooObject> test = new HashMap<>();
test.put(0,new FooObject("first","1 label",false));
//Accessing parameters
test.get(0).isDisabled();
test.get(0).getValue();
test.get(0).getLabel();
While Java does not support default values, you can override constructors to simulate defaults:
FooObject(String value,String label,boolean disabled){
this.value=value;
this.label=label;
this.disabled=disabled;
}
FooObject(String value,String label){
this.value=value;
this.label=label;
//default value
this.disabled=true;
}