使用scala调用java.util.hashtable#put
-
01-10-2019 - |
题
我有一个意想不到的麻烦打电话给老式的楼梯。这里发生了什么?
Welcome to Scala version 2.8.0.final (Java HotSpot(TM) Client VM, Java 1.6.0_21).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import com.ibm.mq._
import com.ibm.mq._
scala> MQEnvironment.properties
res1: java.util.Hashtable[_, _] = {}
scala> res1.put("transport", "MQSeries")
<console>:10: error: type mismatch;
found : java.lang.String("transport")
required: ?0 where type ?0
res1.put("transport", "MQSeries")
^
PS,这个问题仍然像以前一样存在,但我有一个讨厌的解决方法:
scala> new java.util.Hashtable[String, String]
res10: java.util.Hashtable[String,String] = {}
scala> res10.put("transport", "MQSeries")
res11: String = null
scala> MQEnvironment.properties = res10
scala> MQEnvironment.properties
res13: java.util.Hashtable[_, _] = {transport=MQSeries}
解决方案
那 properties
接口似乎是预先Java通用物的那些老式的API之一。这些强调 java.util.HashTable[_, _]
是存在类型的速记,第一个(密钥类型)对应于 ?0
出现在诊断中。这些旧的Java“ RAW”类型是Scala的Java互操作性中不幸的,可见的接缝,尽管通常仅在非常古老的API中出现。
不隶属于 StackOverflow