Hi! I try to create a simple factory method to create a map in a typed way but can’t figure out the correct method syntax. I created a simple example at Try Haxe !
class MapUtil {
public static function createLazy<T,M>( existing : Map<T,M> ) : Map<T,M> {
if ( existing == null ) existing = new Map<T,M>();
return existing;
}
}
class Test {
static function main() {
// Declare typed variable without value
var mapIMightNeed : Map<String,Int> = null;
mapIMightNeed = MapUtil.createLazy( mapIMightNeed );
mapIMightNeed.set( "key", 1 );
}
}
I tried several approaches. So maybe you know how it’s done? I rarely use generics and only with an single type…