Aladdin - Scala Bugtracking
[#158] project: specification priority: low category: missing feature
submitter assigned to status date submitted
Burak Martin won't fix 2003-09-30 11:30:12.0
subject p.47 (type of null)
code
object foo {
  def main = {
    //var ch:char = null.asInstanceOf[char]; this works
    var ch:char = null;
  }
}
what happened
what expected it is more intuitive to C,C++,Java programmers to think of null as being of "the right type" (depending on the context).
this could be implemented in the compiler by adding the cast in an early phase, as needed.
[back to overview]
Changes of this bug report
Burak  edited on  2003-09-30 11:30:22.0
Matthias  edited on  2003-09-30 23:54:47.0
For Java programmers it is clear that null has type null and type null is a subtype of all reference types. In Scala, null has type scala.AllRef (which is a subtype of all subtypes of scala.AnyRef). Consequently, Scala handles null exactly like Java does! So why is it unintuitive? If you want to initialize your variable to a default value, use the following syntax:
var ch: Char = _;
Martin  edited on  2003-10-06 12:38:16.0