一部のJavaコードをDartに移植していますが、次の種類のマップを多用しています。
Map<Class<? extends SomeClass>, SomeOtherClass> map = new HashMap<>();
現時点では、これはダーツでは不可能のようです。私は、第1レベルのタイプを導入する提案があることを認識しています:http : //news.dartlang.org/2012/06/proposal-for-first-class-types-in-dart.html
class Type {
@native String toString();
String descriptor(){...} // return the simple name of the type
}
したがって、この提案が実装されるまで、私は次のクラスを作成しました。
class Type {
final String classname;
const Type(this.classname);
String descriptor() => classname;
}
必要なクラスには単純なgetメソッドがあります
abstract Type get type();
そうType
すれば、実際に使用するのと同じように使用でき、Type
後で切り替えるには、回避策を削除する必要があります。
私の質問:この種のマッピングを行うためのいくつかの方法はありますか(私は見ていません)、または実際のType
クラスが導入されるまでそれを行う方法は合理的な回避策ですか?
Dart1.0のアップデート
これは次のように行うことができます。
var map = new Map<Type, SomeOtherClass>();
// either
map[SomeOtherClass] = new SomeOtherClass();
// or
var instance = new SomeOtherClass();
map[instance.runtimeType] = instance;