{"id":5059,"date":"2014-03-30T18:30:40","date_gmt":"2014-03-30T18:30:40","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-cast-to-a-specified-class-type-duplicate-collection-of-common-programming-errors\/"},"modified":"2014-03-30T18:30:40","modified_gmt":"2014-03-30T18:30:40","slug":"how-to-cast-to-a-specified-class-type-duplicate-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-cast-to-a-specified-class-type-duplicate-collection-of-common-programming-errors\/","title":{"rendered":"How to cast to a specified class type? [duplicate]-Collection of common programming errors"},"content":{"rendered":"<p>The cast as you write it does nothing.<\/p>\n<p>The cast serves for assigning an object of a superclass to a subclass reference<\/p>\n<pre><code>Object obj = a.toString();\nString str = (String) obj;  \/\/ The compiler can't check that at runtime obj will be\n                            \/\/ a String, so the programmer \"forces\" the compiler to\n                            \/\/ allow the assignation\n<\/code><\/pre>\n<p>needs a cast, but in<\/p>\n<pre><code>Object obj2 = (String) obj;\n<\/code><\/pre>\n<p>the cast does nothing (other than throwing a <code>ClassCastException<\/code> if <code>obj<\/code> is not a String).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The cast as you write it does nothing. The cast serves for assigning an object of a superclass to a subclass reference Object obj = a.toString(); String str = (String) obj; \/\/ The compiler can&#8217;t check that at runtime obj will be \/\/ a String, so the programmer &#8220;forces&#8221; the compiler to \/\/ allow the [&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-5059","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5059","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=5059"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5059\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5059"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5059"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5059"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}