My idea was to use casting to get a StringBuilder object to pass a valid argument to a method. Like this:
public TTTButton(String color) {
StringBuilder sb = new StringBuilder();
sb.append("Color."+ color.toString().toUpperCase());
this.setBackground((Color)(Object)sb);// Runtime Exception: java.lang.StringBuilder cannot be cast to java.awt.Color
Please share your thoughts on why such things are impossible (or maybe they are possible)?
Evalfunction.Stringis not aColor. You can perform a lookup, as in my answer to your previous question.sb.append("a" + b)doessb.append(new StringBuilder("a").append(b).toString())under the hood so your explicitStringBuilderis redundant.System.out.println("new java.lang.String(\"foo\")");would be ambiguous.