{"id":410,"date":"2009-07-15T17:30:30","date_gmt":"2009-07-15T09:30:30","guid":{"rendered":"http:\/\/blog.lolyco.com\/sean\/?p=410"},"modified":"2009-07-15T17:30:30","modified_gmt":"2009-07-15T09:30:30","slug":"how-to-get-java-class-name-from-static-code","status":"publish","type":"post","link":"https:\/\/blog.lolyco.com\/sean\/2009\/07\/15\/how-to-get-java-class-name-from-static-code\/","title":{"rendered":"How to get Java class name from static code"},"content":{"rendered":"<p>I thought of one way to do this, but checked Google first to see if there was an easier, more obvious way. <a href=\"http:\/\/www.rgagnon.com\/javadetails\/java-0402.html\">Real Gagnon has a method at his site<\/a> which is similar to the way I thought I could do it, but no less obscure or easy!<\/p>\n<p>Here&#8217;s my code, in case it comes in handy for you:<\/p>\n<p><code>System.out.println(Thread.currentThread()<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;.getStackTrace()[1].getClassName());<\/code><\/p>\n<p>The first (zeroth!) thread in the stack trace is &#8216;java.lang.Thread&#8217;.<\/p>\n<p>It&#8217;s a pity Sun didn&#8217;t use the reserved word &#8216;class&#8217; as the static counterpart to &#8216;this&#8217;. That way it should have been possible to get the name as &#8220;class.getName()&#8221;, which would have been neat. I&#8217;m sure there must be a good reason. Is there?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I thought of one way to do this, but checked Google first to see if there was an easier, more obvious way. Real Gagnon has a method at his site which is similar to the way I thought I could do it, but no less obscure or easy! Here&#8217;s my code, in case it comes [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,20,3],"tags":[33],"class_list":["post-410","post","type-post","status-publish","format-standard","hentry","category-breaktime","category-fixed","category-software","tag-java"],"_links":{"self":[{"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/posts\/410","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/comments?post=410"}],"version-history":[{"count":7,"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/posts\/410\/revisions"}],"predecessor-version":[{"id":417,"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/posts\/410\/revisions\/417"}],"wp:attachment":[{"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/media?parent=410"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/categories?post=410"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/tags?post=410"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}