Class enum

Class enum - Java - Programmation

Marsh Posté le 26-11-2008 à 16:40:15    

Bonjour,
 
Je voulais savoir si une classe enum est chargée et initialisée une seule fois au runtime (cf. ex de classe ci-dessous).
En gros, est-ce que tous ses membres sont statiques ?
 

Code :
  1. public enum MscStoreEnum {
  2. ARCHIVE_SPACES_STORE("archive://SpacesStore", new StoreRef(
  3.   "archive://SpacesStore" )),
  4. SYSTEM_STORE("system://system", new StoreRef("system://system" )),
  5. USER_ALFRESCO_USER_STORE("user://alfrescoUserStore", new StoreRef(
  6.   "user://alfrescoUserStore" )),
  7. WORKSPACE_LIGHTWEIGHTVERSIONSTORE("workspace://lightWeightVersionStore",
  8.   new StoreRef("workspace://lightWeightVersionStore" )),
  9. WORKSPACE_SPACES_STORE("workspace://SpacesStore", new StoreRef(
  10.   "workspace://SpacesStore" ));
  11. private String  storeUrl;
  12. private StoreRef storeRef;
  13. private MscStoreEnum(String pStoreUrl, StoreRef pStoreRef) {
  14.  this.storeUrl = pStoreUrl;
  15.  this.storeRef = pStoreRef;
  16. }
  17. public StoreRef getStoreRef() {
  18.  return storeRef;
  19. }
  20. public String getStoreUrl() {
  21.  return storeUrl;
  22. }
  23. }


---------------
Asus P5Q Pro | C2D E8400 3GHz@4GHz + Noctua NH-C12P | 2x2Go Patriot Extreme PC-8500 | GeForce GTX 460@Stock 1Go GLH | Crucial SSD M4 64Go Sata3
Reply

Marsh Posté le 26-11-2008 à 16:40:15   

Reply

Marsh Posté le 26-11-2008 à 20:30:00    

C'est bon j'ai ma réponse :  
 
   

Citation :

* enums are implicitly final subclasses of java.lang.Enum
    * if an enum is a member of a class, it is implicitly static
    * new can never be used with an enum, even within the enum type itself
    * name and valueOf simply use the text of the enum constants, while toString may be overridden to provide any content, if desired
    * for enum constants, equals and == amount to the same thing, and can be used interchangeably
    * enum constants are implicitly public static final
    * the order of appearance of enum constants is called their "natural order", and defines the order used by other items as well : compareTo, iteration order of values , EnumSet, EnumSet.range.


 
 
Enum c'est du full static  :sol: ! ça c performant !  :D


---------------
Asus P5Q Pro | C2D E8400 3GHz@4GHz + Noctua NH-C12P | 2x2Go Patriot Extreme PC-8500 | GeForce GTX 460@Stock 1Go GLH | Crucial SSD M4 64Go Sata3
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed