Manifest 不可用的情况
def bar[T: Manifest](a: Array[T]) = Array.ofDim[T](3)
class Foo
bar(Array(new Foo)) //Array[Foo] = Array(null, null, null)
清单似乎对于任意类型隐式存在,如上所示。
由于我们有上下文绑定,这意味着将有一些类型没有隐式清单 - 它们是什么?
def bar[T: Manifest](a: Array[T]) = Array.ofDim[T](3)
class Foo
bar(Array(new Foo)) //Array[Foo] = Array(null, null, null)
Manifests seem to exist implicitly for arbitrary types, as shown above.
Since we have a context bound, this implies that there will be some types for which there is no implicit Manifest - what are they?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
清单必须从具体类型最后出现在源代码中的位置“传送”,一直通过类型参数到达需要它的位置。
但凡事都有一个表象。
A Manifest has to be "carried" from the point where the concrete type last appears in the source code, all the way through type parameters to the place where it is required.
But everything has a manifest.
我不确定你的推论是否正确。我还没有见过没有清单的类型,但我见过情况类型推断器似乎无法提供清单。
特别是在像这样的嵌套推理情况下:
似乎除非清单被“传递”,否则它在较低级别不可用 - 因此我们可以说
或
但是,这正是我的行为的原因不知道。
I'm not sure that your deduction is correct. I haven't seen types for which there is no manifest, but I have seen situations where the type inferencer doesn't seem able to provide one.
Specifically in nesting inference situations like this:
It seems that unless the manifest is 'passed around' it isn't available at the lower level - so that we can say
or
However quite why this is the behaviour I don't know.