<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Enums on BradCypert.com</title>
    <link>https://www.bradcypert.com/tags/enums/</link>
    <description>Recent content in Enums on BradCypert.com</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Tue, 27 Dec 2022 16:51:00 -0500</lastBuildDate>
    <atom:link href="https://www.bradcypert.com/tags/enums/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>A Beginner&#39;s Guide to Java Enums</title>
      <link>https://www.bradcypert.com/a-beginners-guide-to-java-enums/</link>
      <pubDate>Mon, 05 Aug 2019 00:00:00 +0000</pubDate>
      <guid>https://www.bradcypert.com/a-beginners-guide-to-java-enums/</guid>
      <description>&lt;p&gt;An Enum in Java is a special data type that encompasses a set of predefined constants. When setting a variable of that Enum type, you have to use one of the constants that you define for it. A great example is the compass:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#282a36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-java&#34; data-lang=&#34;java&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#8be9fd;font-style:italic&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#8be9fd;font-style:italic&#34;&gt;enum&lt;/span&gt; Compass {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  NORTH, EAST, SOUTH, WEST;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Compass direction &lt;span style=&#34;color:#ff79c6&#34;&gt;=&lt;/span&gt; Compass.&lt;span style=&#34;color:#50fa7b&#34;&gt;NORTH&lt;/span&gt;;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In the above example, we create a new enum and it’s predefined set of constants. Then we create a variable of that enum type, and assign it to one of the constants. Keep in mind that we can only set our direction to &lt;code&gt;Compass.NORTH&lt;/code&gt;, &lt;code&gt;Compass.SOUTH&lt;/code&gt;, &lt;code&gt;Compass.EAST&lt;/code&gt; , &lt;code&gt;Compass.WEST&lt;/code&gt; or &lt;code&gt;null&lt;/code&gt;. If we wanted to set our direction to an inter-cardinal direction, we’ll have to add them to our enum, like so:&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
