I cannot understand why this even compile. I've tried with different formats and they all seem to work..
why is it legal to have an enum of enum of enum of..
?
interface I {
enum E implements I {
VAL;
}
class Test {
I.E f1 = I.E.VAL;
I.E.E f2 = I.E.VAL;
I.E.E.E f3 = I.E.VAL;
I.E.E.E.E.E f4 = I.E.VAL;
I.E v1 = I.E.VAL;
I.E v2 = I.E.E.VAL;
I.E v3 = I.E.E.E.E.E.E.VAL;
I.E v4 = I.E.E.E.E.E.E.E.E.E.E.VAL;
}
}
My IDE reports it compiles just fine, although I.E.E
does not make sense to me.
Yes, we can define an enumeration inside a class. You can retrieve the values in an enumeration using the values() method.
This technique is absolutely thread-safe. An enum value is guaranteed to only be initialized once, ever, by a single thread, before it is used.
The main objective of enum is to define our own data types(Enumerated Data Types). Declaration of enum in Java: Enum declaration can be done outside a Class or inside a Class but not inside a Method.
Enumerations make for clearer and more readable code, particularly when meaningful names are used. The benefits of using enumerations include: Reduces errors caused by transposing or mistyping numbers. Makes it easy to change values in the future.
Your I
interface contains an enum type named E
.
This type implements that same I
interface, so it inherits everything that that interface contains.
This includes the E
type itself.
In other words, I.E.E
is accessing I.E
as inherited by E
from the outer I
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With