Let's say I've got:
var pairOfObjects = ListBuffer("", myDate)
Where myDate is of type java.util.Date, and it's value is 1970-01-01T00:00:00.000-00:00
Putting that into the Scala REPL tells me:
pairOfObjects: scala.collection.mutable.ListBuffer[Comparable[_ >: java.util.Date with String <: Comparable[_ >: java.util.Date with String <: java.io.Serializable] with java.io.Serializable] with java.io.Serializable] = ListBuffer("", Wed Dec 31 16:00:00 PST 1969)
I'd expect it to be something like ListBuffer[Any]. In fact, when I put in:
var pairOfObjects = ListBuffer("", 1)
The Scala REPL does give me:
pairOfObjects: scala.collection.mutable.ListBuffer[Any] = ListBuffer("", 1)
Why does putting in a Date object to the ListBuffer result in such a complicated type?
A List in Scala is covariant.
Example for Int and Double are subtypes of Double, then List[Int] and List[Double] are also subtypes of List[Double].
Here is the definition for
stringin scala fromPredefobjectJava
Stringclass declartionjava.util.dateclass declartionNow after looking into these definitions both
DateandStringclass in java are inherited classes fromjava.io.Serializableand not fromAnydirectly so you don't seeListBuffer[Any]when the list elements areDateandString.Thereby from these statement
scala.collection.mutable.ListBuffer[Comparable[_ >: java.util.Date with String <: Comparable[_ >: java.util.Date with String <: java.io.Serializable] with java.io.Serializable] with java.io.Serializable] = ListBuffer("", Wed Dec 31 16:00:00 PST 1969)Anyis lower type bound tojava.util.datewithStringwhich are upper bound tojava.io.Serializable