我嘗試實現相當於Java使用typeof(SomeClass的)
Hashtable<string, -Typeof one Class->
在Java中
。但我不知道如何使這個工作。我試過
Hashtable<String, AbstractRestCommand.class>
但這似乎是錯誤的。
Btw。我希望這在運行時爲每個反射創建一個新的類實例。
所以我的問題是,如何做這種東西。
編輯:
我有抽象類 「AbstractRestCommand」。現在我想創建有很多命令的哈希表是這樣的:
Commands.put("PUT", -PutCommand-);
Commands.put("DELETE", -DeleteCommand-);
其中PutCommand和DeleteCommand延伸AbstractRestCommand,這樣我就可以用
String com = "PUT"
AbstractRestCommand command = Commands[com].forName().newInstance();
...
你的意思'哈希表<字符串,AbstractRestCommand>'? – BalusC 2011-05-30 20:56:33