Why is it not possible to construct arguments to methods using Strings? [duplicate]-Collection of common programming errors
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)?