Stand Alone Enums???

C

chris.allport

I am trying to "globally" declare an enum so I can use it across a
large application. This is an example of what I have tried:


/** File: TestEnum.java ********/
public enum TestEnum {
ONE,
TWO,
THREE,
FOUR;
}


/** File: TestClass.java **********/
public class TestClass {
TestEnum number;

public void setNum(TestEnum num) { number = num; }
public TestClass getNum() { return number; }

}

--

The TestEnum is not being recognized as a valid type ("cannot find
symbol").

Any ideas on a good implementation of this?

Thanks in advance!
 
R

Roland

I am trying to "globally" declare an enum so I can use it across a
large application. This is an example of what I have tried:


/** File: TestEnum.java ********/
public enum TestEnum {
ONE,
TWO,
THREE,
FOUR;
}


/** File: TestClass.java **********/
public class TestClass {
TestEnum number;

public void setNum(TestEnum num) { number = num; }
public TestClass getNum() { return number; }
^^^^^^^^^
public TestEnum getNum() { return number; }
}

--

The TestEnum is not being recognized as a valid type ("cannot find
symbol").

Any ideas on a good implementation of this?

Thanks in advance!
Return type of getNum() should be TestEnum.

If TestClass.java still doesn't compile (if you still get "cannot find
symbol"), specify your classpath with -classpath option, e.g.:
javac -classpath . TestClass.java

HTH,
--
Regards,

Roland de Ruiter
___ ___
/__/ w_/ /__/
/ \ /_/ / \
 
C

chris.allport

Sorry, that was just a typo.

Still not working.

I created a third file "Thing.java" that implements a simple class and
create one in "TestClass." This object is found. The "enum" still is
not.
 
C

chris.allport

Hmm.. Nevermind. All of the sudden, it is compiling and working!? Of
course, I have NO idea what I changed, because those files compare the
same.

Thanks for the assistance!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,044
Latest member
RonaldNen

Latest Threads

Top