Enum question

I'm attempting to create a simple class that loads a model from the enum however when i call it in the main class all three models load at once.

A later goal is to clone each model from the first time the method is called so theirs a reference to each in memory since their would be more than one instance of that character at a time. Is this actually what I want it to do I'm unsure??




package com.tps1.GameState;

import java.util.concurrent.ExecutionException;
import java.util.logging.Logger;

import com.jmex.game.StandardGame;
import com.jmex.game.state.GameState;
import com.jmex.game.state.GameStateManager;
import com.tps1.GameState.SkyBoxManager.SkyBoxGameState;


public class Charactertype extends playerGameState {   
     public static enum type {
        AVENGER("ninja"),
        SENTINAL("robot"),
        PHANTOM("fish");    
       
        private type(String theName)
        {
          Charactertype.init(theName);          
           GameState Charactertype = new Charactertype(theName);
           GameStateManager.getInstance().attachChild(Charactertype);
              Charactertype.setActive(true);

        }
        public void build()
        {
           Charactertype.get();
        }
     }
    
    
    private static Logger logger = Logger.getLogger(Charactertype.class.getName());
   
    // the one and only instance of the Charactertype class
    private static Charactertype instance = null;
   
    // this string finds the model and loads it
    private String strType=null;

    // init must be called once when the game starts
    // after that the Charactertype can be accessed from everywhere with
    // Charactertype.get()
    public static void init(String characterType) {
        instance = new Charactertype(characterType);
    }
   
    public static Charactertype get() {
        if (instance == null) {
            // init has not been called yet.
            logger.severe("ALERT, call init first!!");
        }
        return instance;
    }
   
    // the constructor is private, it can only be called inside this class
    private Charactertype(String type){
         super(type);
        this.strType = type;
     
        setupCharacter();
    }

    private void setupCharacter(){
       
    }
   
    // return the character name type
    public String getCharactertype() {
      return strType;
    }
   
   
   
   
   
   
   
    public static void main(String[] args) throws InterruptedException, ExecutionException {
       StandardGame standardGame = new StandardGame("GameControl", StandardGame.GameType.GRAPHICAL, null);
        standardGame.start();
   
       try {
         SkyBoxGameState.Manager().setActive(true);
      } catch (Exception e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
      type.AVENGER.build();
      //type.SENTINAL.get();
      //type.PHANTOM.get();
   

    }
}

Enum things (each entry, not sure of the proper term) are singletons - there will only ever be one of them, and their constructors are called when the class is loaded, not when you access them (which is why all 3 are initialised together) - they are also have a final clone method so can't be cloned.



Not really sure what you are trying to achieve here but seems awfully overcomplicated  :?

JOC said:

Enum things (each entry, not sure of the proper term) are singletons - there will only ever be one of them, and their constructors are called when the class is loaded, not when you access them (which is why all 3 are initialised together) - they are also have a final clone method so can't be cloned.

Not really sure what you are trying to achieve here but seems awfully overcomplicated  :?



lol nah I was actually trying K.I.S.S when using them but i realized that using the enum in such a manner wouldn't work and would be easier to call when needed as for cloning should I make it in the class written above that the first time its called it loads that model and gives a clone to instance?? correct or will it keep loading models and creating another clone everytime i did if say


charactertype avenger = new charactertype("avenger")
Gametaskmanager" '' " ".attach(avenger)
avenger.setActive(true)


or should i do something along the lines of
everything i did above plus a new method
avenger.newClone()
every time I want an instance of that charactertype

but then how would i bind each new clone to a specific I/O controller maybe do
Object player1 = avenger.newClone();
btw I'm using ogre

any suggestions