我试图abstract通过实现Set数据类型来解决这个问题,如下所示:
abstract Set<T>(Map<T, Bool>) {
public inline function new() {
this = new Map<T, Bool>();
}
public inline function has(item:T):Bool {
return this.exists(item);
}
public inline function add(item:T):Set<T> {
this.set(item, true);
return null;
}
public inline function remove(item:T):Set<T> {
this.remove(item);
return null;
}
public inline function iterator():Iterator<T> {
return this.keys();
}
}
Run Code Online (Sandbox Code Playgroud)
但编译器并不喜欢这样.它告诉我Set.hx:8: characters 11-29 : Abstract Map has no @:to function that accepts IMap<util.Set.T, Bool>
我根本不理解这一点,因为如果我将构造函数更改为
public inline function new(val:Map<T, Bool>) {
this = …Run Code Online (Sandbox Code Playgroud)