scala integer weirdness

Posted by williamstw on Stack Overflow See other posts from Stack Overflow or by williamstw
Published on 2010-06-06T22:55:13Z Indexed on 2010/06/06 23:02 UTC
Read the original article Hit count: 398

Filed under:

Suppose you inadvertently use Integer instead of Int, as in this code:

import scala.collection.mutable.Map

val contributors = Map[String,Integer]()

val count = contributors.getOrElseUpdate("john",0)

contributors.put("john",count+1)

println(contributors)

Compiler output:

(fragment of test.scala):7: error: type mismatch;
found   : Int(1)
required: String
contributors.put("john",count+1)
                           ^

Why "required: String"?

© Stack Overflow or respective owner

Related posts about scala