ActionScript 中的泛型(返回类型与参数类型相同)

发布于 2025-01-07 12:26:13 字数 167 浏览 1 评论 0原文

是否可以指定函数的返回类型与未知参数类型之一的参数类型相同。例如:

class Factory {
    public function get(interface:*):Object {
    }
}

上面的问题是我必须一直将对象强制转换为接口。

Is it possible to specify that a return type of a function is the same as one of the parameter types where it is unknown what the parameter type is. For example:

class Factory {
    public function get(interface:*):Object {
    }
}

The problem with the above is that I have to cast the object to interface all the time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

驱逐舰岛风号 2025-01-14 12:26:13

你能做到吗?:

function example(type:*):*
{
    return type;
}

似乎不需要转换:

trace(example(new Sprite()).alpha); // 1

Can you do this?:

function example(type:*):*
{
    return type;
}

Doesn't seem to require casting:

trace(example(new Sprite()).alpha); // 1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文