Показать сообщение отдельно
Старый 12.07.2011, 18:45
fljot вне форума Посмотреть профиль Отправить личное сообщение для fljot Найти все сообщения от fljot
  № 1  
Ответить с цитированием
fljot

блогер
Регистрация: Jul 2007
Сообщений: 940
Записей в блоге: 3
По умолчанию Тип Vector.<*> в роли аргумента

Векторы доступны уже года два наверное, а я до сих пор не могу понять как же так.

Код AS3:
var v:Vector.<Sprite> = new Vector.<Sprite>();
trace(v is Vector.<*>);// true
var foo:Vector.<*>;
//foo = v;// Implicit coercion of a value of type __AS3__.vec:Vector.<flash.display:Sprite> to an unrelated type __AS3__.vec:Vector.<*>.
foo = v as Vector.<*>; // OK
var bar:Vector.<Sprite> = foo as Vector.<Sprite>;// OK
 
genericArgument(v);// true, 0, Hello from genericArgument()
//typedArgument(v);// Implicit coercion of a value of type __AS3__.vec:Vector.<flash.display:Sprite> to an unrelated type __AS3__.vec:Vector.<*>.
 
function genericArgument(value:*):void
{
	var foo:Vector.<*> = value as Vector.<*>;
	trace(foo is Vector.<*>, foo.length); // true, 0
	trace("Hello from genericArgument()");
}
 
function typedArgument(value:Vector.<*>):void
{
	trace("You won't see this message");
}


Последний раз редактировалось fljot; 12.07.2011 в 19:32. Причина: Добавил foo, bar