简体   繁体   中英

SuperClass change type variable SubClass

I'm have a question in my projects, bellow is my class:

class BasePlayer {
    ...
}

class Player extend BasePlayer {
    ...
}

class BasePlayerManager {
    private List<BasePlayer> players;

    public BasePlayer getPlayerById() {

    }

    public List<BasePlayer> getPlayers() {
        return players;
    }
}

class PlayerManager extend BasePlayerManager {

}

I need a solution in class PlayerManager. I can get as:

PlayerManager playerManager = new PlayerManager();
Player player = playerManager.getPlayerById();

Anyone can help me? I do not want to rewrite function getPlayerById .

Thanks you

your questions is not in proper way, if your intension to get or call getPlayerById() in PlayerManager, you can call it directly or override the getPlayerById() since PlayerManager is subclass of BasePlayerManager.

Super class methods which is public or protected can call directly into subclass

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM