#Singleton is it possible to check it in different ways

1 messages · Page 1 of 1 (latest)

tame hedge
#

Im using a singleton for a player character and want to know if i can do different methods for checking the singleton instance

public class Player extends Entity{
    keyHandeler key;


    private static Player instance = null;
    public static Player getInstance(Panel pnl, keyHandeler key){
        if(instance == null){
            instance = new Player(pnl,key);

        }
        return instance;
    }
    public static Player getInstance(Panel pnl){
        if(instance == null){
            instance = new Player(pnl);

        }
        return instance;
    }
    private Player(Panel pnl, keyHandeler key) {
        super(pnl);
        this.key = key;

        solidArea = new Rectangle();
        solidArea.x = 8;
        solidArea.y = 16;
        solidAreaDefaultX= solidArea.x;
        solidAreaDefaultY = solidArea.y;
        solidArea.width = 32;
        solidArea.height = 32;

        setDefaultValues();
        getPlayerImage();
    }

    private Player(Panel pnl) {
        super(pnl);

    }  ```
queen martenBOT
#

This post has been reserved for your question.

Hey @tame hedge! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.