pattern matching - scala Nil type matchs against arraybuffer -
i found strange working construct in scala:
(arraybuffer[int]():seq[int]) match { case nil => "whoo" case _ => "nayyy" }
which returns
"whoo"
apparently works partially for vectors, not pattern matching. can explain me that? nil
does not have method named unapply. how possible?
with objects, unapply
not involved (that case if had used hypothetical case nil() => ...
). instead, equality checked using equals
method.
equality collections defined in terms of elements. e.g.
list(1,2,3) == vector(1,2,3) // true!
the same happens nil
equals empty sequence:
vector() == nil // true collection.mutable.arraybuffer() == nil // true
Comments
Post a Comment