Scala: can't write setter without getter?
        Posted  
        
            by IttayD
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by IttayD
        
        
        
        Published on 2010-03-15T12:46:42Z
        Indexed on 
            2010/03/15
            12:49 UTC
        
        
        Read the original article
        Hit count: 258
        
scala
This works:
class ButtonCountObserver {
  private var cnt = 0  // private field
  def count = cnt      // reader method
  def count_=(newCount: Int) = cnt = newCount  // writer method
 // ...
}
val b = new ButtonCountObserver 
b.count = 0
But this doesn't class ButtonCountObserver { private var cnt = 0 // private field def count_=(newCount: Int) = cnt = newCount // writer method // ... }
val b = new ButtonCountObserver 
b.count = 0
I get: error: value count is not a member of ButtonCountObserver
Is it possible to create a setter (with the syntactic sugar) without a getter?
© Stack Overflow or respective owner