{"id":5398,"date":"2014-03-30T21:27:20","date_gmt":"2014-03-30T21:27:20","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/why-is-it-not-possible-to-construct-arguments-to-methods-using-strings-duplicate-collection-of-common-programming-errors\/"},"modified":"2014-03-30T21:27:20","modified_gmt":"2014-03-30T21:27:20","slug":"why-is-it-not-possible-to-construct-arguments-to-methods-using-strings-duplicate-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/why-is-it-not-possible-to-construct-arguments-to-methods-using-strings-duplicate-collection-of-common-programming-errors\/","title":{"rendered":"Why is it not possible to construct arguments to methods using Strings? [duplicate]-Collection of common programming errors"},"content":{"rendered":"<p>My idea was to use casting to get a StringBuilder object to pass a valid argument to a method. Like this:<\/p>\n<pre><code>public TTTButton(String color) {\n    StringBuilder sb = new StringBuilder();\n    sb.append(\"Color.\"+ color.toString().toUpperCase());\n    this.setBackground((Color)(Object)sb);\/\/ Runtime Exception: java.lang.StringBuilder cannot be cast to java.awt.Color \n<\/code><\/pre>\n<p>Please share your thoughts on why such things are impossible (or maybe they are possible)?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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(&#8220;Color.&#8221;+ 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5398","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5398","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5398"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5398\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}