Java equivalent of js object[key] lookup


#1

Just started making this Java Swing interface to control lots of parameters in a separate window from my sketch. Is there a way in Java to make references closer to this old jQuery code I made a
while ago with ToneJS:

the dataset comes from my custom html attributes.
`

effects = {"delay": delay, "trem": trem, "soundFilter": soundFilter};

$("input[type='range']").on("input", function() {
        effects[this.dataset.module][this.id][this.dataset.suffix] = this.value;
    }
});
`

Module = effects key(ref to object to modify), id = param(time, rate, etc), suffix is ‘value’ or ‘’ if no value suffix needed.

This handled lots of sliders and worked as I expected without the need of if statements or a switch statement.

Is it possible to do something similar in Java instead of object(dot)property?


#2

Since the variables’ being assigned to the object’s properties match the names of the properties, we can use a much shorter object creation for it: :wink:

effects = { delay, trem, soundFilter };

Each field (property) of a Java object got its own datatype.
And Java objects are created via instantiating a class.
Which in turn got the description of the fields which will be present on that object.

If by chance the properties of that effects object share the same compatible datatype, we can use a HashMap container to hold those properties’ values: :hash:

Processing.org/reference/HashMap.html