- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Getters and Setters
Fri, 2009-01-16, 18:12
Why doesn't the compiler allow you to have a setter without
corresponding getter? For example in this code:
if I comment out the line
Sam Reid
object TestSetter {
def main(args: Array[String]) = {
class Time{
var h=12
def hour:Int=h
def hour_=(x:Int)={h=x}
}
val t=new Time
t.hour = 123
}
}
if I comment out the line
def hour:Int=hthen compilation fails. Why is this?
Sam Reid