Created
January 10, 2012 14:16
-
-
Save hotpotato/1589287 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Future<T> { | |
var t:T; | |
public function new () {} | |
public function setValue (t:T) { this.t = t; } | |
} | |
class Futures { | |
public static function create<T>():Future<T> return new Future<T>() | |
} | |
class FuturesInt { | |
public static function withFuture(f:Future<Int>, i:Int):Int return i | |
} | |
class FuturesString { | |
public static function withFuture(f:Future<String>, s:String):String return s | |
} | |
using Example.FuturesInt; // takes precedence over FuturesString when type is Unknown | |
using Example.FuturesString; | |
class Example { | |
public static function main() | |
{ | |
// works as expected when used with constructor | |
new Future<String>().withFuture("hi"); | |
// this is the suggested feature, but it is currently not allowed | |
Futures.asFuture<String>().withFuture("hi"); // Unexpected ) | |
// this cannot work, because T is unknown and because of that the compiler uses the first version of withFuture which expects an Int | |
Futures.create().withFuture("hi"); // String should be Int | |
// dirty workaround with a temp variable | |
var f:Future<String> = Futures.create(); | |
f.withFuture("hi"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment