<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: constant code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Mon, 21 Jul 2008 07:41:46 GMT</pubDate>
    <description>DZone Snippets: constant code</description>
    <item>
      <title>Obtaining the value of a public static field by reflexion </title>
      <link>http://snippets.dzone.com/posts/show/4501</link>
      <description>// Obtaining the value of a static public constant of a class, here Boolean for example&lt;br /&gt;&lt;code&gt;&lt;br /&gt;        Object returnedObj = null;&lt;br /&gt;        try {&lt;br /&gt;            Class clazz = Class.forName("java.lang.Boolean");&lt;br /&gt;            returnedObj = clazz.getField("TRUE").get(clazz);&lt;br /&gt;            assert java.lang.Boolean.TRUE == returnedObj : "wrong returned object";&lt;br /&gt;        } catch (ClassNotFoundException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } catch (SecurityException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } catch (NoSuchFieldException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } catch (IllegalArgumentException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } catch (IllegalAccessException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        return returnedObj;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 06 Sep 2007 14:59:06 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4501</guid>
      <author>Archanciel (Jean-Pierre Schnyder)</author>
    </item>
    <item>
      <title>Constants in python</title>
      <link>http://snippets.dzone.com/posts/show/737</link>
      <description>From Alex's &lt;a href=http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65207&gt;recipe&lt;/a&gt;.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# Put in const.py...:&lt;br /&gt;class _const:&lt;br /&gt;    class ConstError(TypeError): pass&lt;br /&gt;    def __setattr__(self,name,value):&lt;br /&gt;        if self.__dict__.has_key(name):&lt;br /&gt;            raise self.ConstError, "Can't rebind const(%s)"%name&lt;br /&gt;        self.__dict__[name]=value&lt;br /&gt;import sys&lt;br /&gt;sys.modules[__name__]=_const()&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;that's all -- now any client-code can&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import const&lt;br /&gt;const.magic = 23     # bind an attribute ONCE&lt;br /&gt;const.magic = 88     # raises const.ConstError if re-bind&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Sun, 18 Sep 2005 13:35:51 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/737</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
