문제

What should I do when I get this?

java.lang.ClassCastException: org.apache.commons.collections.set.UnmodifiableSet 
    cannot be cast to scala.collection.immutable.Set
도움이 되었습니까?

해결책

You can't cast between them, but you should be able to use the scala.collection.JavaConverters to convert java.util.Set (UnmodifiableSet implements this) => mutable.Set, and then call .toSet to convert to an immutable.Set, eg:

import org.apache.commons.collections.set.UnmodifiableSet
import scala.collection.JavaConverters._
val u = new UnmodifiableSet()
val s = u.asScala.toSet
println(s)

see: http://www.scala-lang.org/api/current/index.html#scala.collection.JavaConverters

(Alternatively use JavaConversions and the asScala can happen implicitly - explicit generally better)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top