For Programmers: Free Programming Magazines  


Home > Archive > Java Help > June 2005 > Can i refer to an ENUM from another class?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Can i refer to an ENUM from another class?
Konrad Viltersten

2005-06-05, 8:57 am

I have following code in class A
enum SOMETHING {some1, some2, some3}

Now, i create an object of that class by
A a = new A ();

I wish then to use the values of SOMETHING as follows
.... = a.some1;
or
.... = a.SOMETHING.some1;
or something similar.

However, the compiler diagrees with me by
"cannot find symbol variable some1"

What do i do uncleaverly?

--

Vänligen
Konrad
---------------------------------------------------

Sleep - thing used by ineffective people
as a substitute for coffee

Ambition - a poor excuse for not having
enough sense to be lazy

---------------------------------------------------

John McGrath

2005-06-05, 3:58 pm

On 6/5/2005 at 4:51:50 AM, Konrad Viltersten wrote:

> I have following code in class A
> enum SOMETHING {some1, some2, some3}
>
> Now, i create an object of that class by
> A a = new A ();
>
> I wish then to use the values of SOMETHING as follows
> ... = a.some1;
> or
> ... = a.SOMETHING.some1;
> or something similar.
>
> However, the compiler diagrees with me by
> "cannot find symbol variable some1"


A.SOMETHING.some1

While you can use an class reference variable (i.e. "a") to qualify
the name of a static field, you cannot use one to qualify then name
of a nested type.

--
Regards,

John McGrath
Konrad Viltersten

2005-06-05, 8:57 pm

>> enum SOMETHING {some1, some2, some3}
>
> A.SOMETHING.some1
>
> While you can use an class reference variable (i.e. "a") to qualify
> the name of a static field, you cannot use one to qualify then name
> of a nested type.



Thanks.

--

Vänligen
Konrad
---------------------------------------------------

Sleep - thing used by ineffective people
as a substitute for coffee

Ambition - a poor excuse for not having
enough sense to be lazy

---------------------------------------------------

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com