I am curious why the error occurred:
scala> import collection.JavaConverters._
import collection.JavaConverters._
scala> val m = Map("one"->1)
m: scala.collection.immutable.Map[String,Int] = Map(one -> 1)
scala> val jm = m.asJava
jm: java.util.Map[String,Int] = {one=1}
scala> val hm = new java.util.Hashtable(jm)
<console>:12: error: type mismatch;
found : java.util.Map[String,Int]
required: Int
val hm = new java.util.Hashtable(jm)
^
scala> import java.util._
import java.util._
scala> val hm: Dictionary[String,Int] = new java.util.Hashtable(jm)
hm: java.util.Dictionary[String,Int] = {one=1}
The original question is here.
It is too late at night to view the congestion.
Incorrect speculation:
It must choose between constructors that accept an int or collection. There seems to be a more specific method for a polymorphic method with a more specific type of result. Perhaps Hashtable<K, V>()more specific than Hashtable<String, Integer>because it can be <K,V>more specific than <String, Integer>, but not vice versa.
No, it is not:
implicitly[Hashtable[String,Integer] <:< Hashtable[_,_]]
Actually ctor
public Hashtable(Map<? extends K, ? extends V> t)
source
share