I'm trying to call my Scala Util
object from Java code:
Main.java
Set<Long> items = new HashSet<Long>();
// fill up items with Long
MyUtil.foo(100, items);
Util.scala
object Foo {
type Id = Long
def foo(id: Id, items: scala.collection.mutable.Set[Id])
Here's the compile-time error:
could not parse error message:
required: long,scala.collection.mutable.Set<Object>
found: Long,java.util.Set<Long>
reason: actual argument java.util.Set<Long> cannot be converted to
scala.collection.mutable.Set<Object> by method invocation conversion`
From reading these Java to Scala Collections docs, I am using a mutable
Set rather than the default, immutable Set:
scala.collection.mutable.Set <=> java.util.Set
But, I don't understand the error message. By using a Long
(boxed long
) in my Java code, why is a Set<Long>
found?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…