Calling Scala Method from Java - Set<Object> or Set<Long>? -
java
set<long> set = new hashset<long>(); set.add(100); long x = 2; foo(x, set);
scala
def foo(a: long, b: java.util.set[long])
error:
could not parse error message: required: long,set<object> found: long,set<long> reason: actual argument set<long> cannot converted set<object> method invocation conversion
then, modified java code resolve compile-time error.
set<object> set = new hashset<object>();
however, resolution of compile-time error came @ expense of type safety. how can resolve above error?
edit
after @som-snytt resolved issues here, ran problem. don't think it's same question since , in linked question, using, in scala, foo(long, java.util.set[long])
worked when calling (from java) scalaobject.foo(long, set[long])
the types wrong. type of set
in java code java.util.set[java.lang.long]
, while type in scala java.util.set[scala.long]
. scala.long
type treated primitive long
in java, when not erased, , java.lang.object
when erased (as uncovered).
so either change scala's type java's type match. it's unfortunate scala.long
erases java.lang.object
, necessary.
Comments
Post a Comment