3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GenericStackをTypeParameter混じりのstaticな関数として扱うと、関数参照を渡せなくなる

Last updated at Posted at 2013-07-08
Test.hx
import haxe.ds.GenericStack;
class Test 
{
	var arrayFunctionHolder:Array<String> -> Void;
	var stackFunctionHolder:GenericStack<String> -> Void;
	
	static public function arrayFunction<T>(param:Array<T>):Void
	{
	}
	
	static public function stackFunction<T>(param:GenericStack<T>):Void
	{
	}
	
	static public function stackFunction2(param:GenericStack<String>):Void
	{
	}
	
	public function new()
	{
		arrayFunctionHolder = arrayFunction;	// ok
//		stackFunctionHolder = stackFunction;	// error...
//		stackFunctionHolder = stackFunction<String>;	// error...
//		stackFunction<String>(new GenericStack<String>());	// error...
		stackFunction2(new GenericStack<String>());	// ok
		var hoge:Hoge<String> = new Hoge(stackFunction);	// ok...
	}
}
class Hoge<T>
{
	public var hoge2:Hoge2<T>;
	public function new(func:GenericStack<Hoge2<T>> -> Void) 
	{
		hoge2 = new Hoge2<T>();
	}
}
class Hoge2<T>
{
	public var stackFunctionHolder:GenericStack<T>;
	public function new() 
	{
	}
}

(´・ω・`)

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?