作者macbuntu (邀怪)
看板java
标题Re: [分享] 原来 Void 可以这样用
时间Sat Mar 14 00:53:26 2009
※ 引述《godfat (godfat 真常)》之铭言:
: 於是 Void 就会是所有 class 的 subclass, 然後就可以在任何 overriding
: method 中把 return type 写成 Void, 因此,就只能够 return null; 也就是
: Void 唯一可能的 value (instance), 而这个 Void instance (null),
: 同时也是其他任何 pointer/reference 的可能 value, 因为他是 Void 的
: instance, class hierarchy 的最底层,相对於 Object 在最顶层。
如果 Java 真的放了一个这样的 Void, 会破坏了现在严谨的继承架构,
而且除非是 syntax based template, 否则一个真的 wildcard class 已经不能
算是符合 covariant return type 的限制了, 从语意到 compiler 都只能当
例外状况处理, 这样就不划算了.
话说回来, 印象中 Scala 就有这种 wildcard type?
它还真的有一个 Null class 跟 Nothing class 是 class hierarchy 的最底层,
不过我不会写 Scala, 我不知道这只是 internal class 还是 programmer 可以直接
使用的型别... 如果 programmer 可以使用, 真好奇 covariant arguments 遇到
这种型别要怎麽处理?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.165.166.80