This is my third (and hopefully final) question today.
Is it possible to declare the value of a variable to the variable of a class, where the name of the class is a string?
Example
int newalpha;
String color_name = "yellow";
Color red = new Color();
Color yellow = new Color();
Color blue = new Color();
newalpha = color_name.alpha
In this example, “.alpha” is a variable contained inside of the Color class. The part I’m wanting to simulate is the “newalpha = color_name.alpha”, because obviously “color_name” is a String, not a color. Is this possible?
Thanks
TL;DR answer: no.
Reality: yes, sort of, via reflection, and ew.Depending on your use case, there may be a way to achieve what you want, like by storing the colors in a hash map with the color names as the keys, so you’d just say
colors.get(colorName).alpha.