Java: Dynamically Load Multiple Versions of Same Class

前端 未结 7 960
一整个雨季
一整个雨季 2021-01-01 01:14

What I\'d like to be able to do is to load set of classes, probably all in the same folder. All of which implement the same interface and are the same class, then in my code

7条回答
  •  长情又很酷
    2021-01-01 01:54

    Have you tried something like:

    class Move;   // some data type that is able to represent the AI's move.
    
    interface AI {
    
        Move getMove( GameState state);
    };
    
    AIOne implements AI;
    AITwo implements AI;
    

    Each class would implement its own algorithm for generating a move, but would be called but called by common method

提交回复
热议问题