首先,我必须说我对Java真的很陌生.所以所有人都道歉,如果我的问题听起来很愚蠢,但到目前为止我还没有找到解决方案…
我想动态实例化一个抽象类的子类.
这是代码
public class CommandMap implements Handler.Callback
{
private HashMap > __commandHashMap;
protected CommandMap()
{
__commandHashMap = new HashMap>();
}
/**
* Map an ID to a command
* @param what Id used in the Message sent
* @param command Command to be executed
*/
public void mapWhat(Integer what, Class extends AbstractCommand> command)
{
if ( !__commandHashMap.containsKey(what) )
{
__commandHashMap.put(what, command);
}
}
/**
* Unmap the id/command pair
* @param what Id
*/
public void unmapWhat(Integer what)
{
if ( __commandHashMap.containsKey(what) )
<