constant

Java enum examples/tutorial (an enum reference page)

Java enum FAQ: Can you share some Java enum examples, such as how to declare a Java enum, and how to use a Java enum in a for loop, if then statement, and Java switch statement?

As described in Sun's Java documentation, a Java enum "is a type whose fields consist of a fixed set of constants ... you should use enum types any time you need to represent a fixed set of constants." Let's take a look at some Java enum examples to see how this works.

A Java enum toString example alvin September 18, 2009 - 7:13pm

Java enum FAQ: Can you share a Java enum toString example?

I haven’t tried this before, but I was just working on several Java enum examples (Java enum examples tutorial, Java enum switch example), and I thought I’d take a look at the Java enum toString behavior.

To that end I wrote the following Java enum “toString” example class:

Ruby NameError: uninitialized constant error message

Problem: When working with some Ruby code in an irb session, I just got the following error message:

NameError: uninitialized constant Tempfile

Here's a snippet of my irb session where this error occurred:

>> tmp = Tempfile.new
NameError: uninitialized constant Tempfile
	from (irb):1

Solution

This "NameError: uninitialized constant" looks intimidating, but it's actually not a big deal: I just forgot to require the tempfile package.