Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis+ 9
What is the difference between class & enum class in Java???
4 Respostas
+ 4
Md. Nasir Uddin
InĀ Java, aĀ classĀ can only extend one parent and therefore anĀ enumĀ cannot extend any otherĀ classĀ (but implement interfaces). Extending EnumĀ means that everyĀ enumĀ has a few methods that make it more usable: static values() static valueOf(String)
source:
https://www.sitepoint.com/fundamentals-of-java-enum-types-tutorial/
I hope I was helpful
+ 4
John Championš¤š„ Please just paste a link to the source you are copying your answers from.
https://stackoverflow.com/questions/15734225/what-are-the-differences-between-a-java-enum-and-a-class-with-private-constructo/15734503#15734503
+ 3
David Carroll ..
Noted
+ 1
Enums extendĀ java.lang.Enumand gain all of itsĀ nice features:
Automatic singleton behaviour through correct serialization
Automatic human-readableĀ .toStringĀ method on enum values without the need to duplicate your enum names
.nameĀ andĀ .ordinalĀ special-purpose methods
Usable in high-performance bitset-basedĀ EnumSetĀ andĀ EnumMapĀ classes
Enums are treated by the language specially:
Enums use a special syntax which simplifies instance creation without writing dozens ofĀ public static finalĀ fields
Enums can be used inĀ switchĀ statements
Enums cannot be instantiated outside the enumeration list except by using reflection
Enums cannot be extended outside the enumeration list
Java automatically compiles extra stuff into enums:
public static (Enum)[] values();
public static (Enum) valueOf(java.lang.String);
private static final (Enum)[] $VALUES;(values()Ā returns a clone of this)
Most of these can be emulated with a suitably designed class, butĀ Enumjust makes it really easy to create a class