(just started with Scala a few weeks ago, so bear with me)
Reading/trying out this little article here, ran into some surprises
http://danielwestheide.com/blog/2012/12/19/the-neophytes-guide-to-scala-part-5-the-option-type.html
After defining a case class User as described:
case class User(
id: Int,
firstName: String,
lastName: String,
age: Int,
gender: Option[String])
object UserRepository {
private val users = Map(1 -> User(1, "John", "Doe", 32, Some("male")),
2 -> User(2, "Johanna", "Doe", 30, None))
def findById(id: Int): Option[User] = users.get(id)
def findAll = users.values
}
, here are the gets I observe:
> scala> UserRepository.findById(1)
> res34: Option[User] = Some(User(1,John,Doe,32,Some(male)))
>
> scala> UserRepository.findById(1).get
> res35: User = User(1,John,Doe,32,Some(male))
>
> scala> UserRepository.findById(1).getOrElse("N/A")
> res36: java.io.Serializable = User(1,John,Doe,32,Some(male))
>
> scala> UserRepository.findById(3).getOrElse("N/A")
> res37: java.io.Serializable = N/A
The first two are what I expected, but the second two aren't; both the case of existing and non-existing Users. Why java.io.Serializable, all of the sudden?