Use scala.collection.JavaConversions from inside of java.
For example to create a nested scala case class that requires a scala List in its constructor:
case class CardDrawn(player: Long, card: Int)
case class CardSet(cards: List[CardDrawn])
From Java you can use asScalaBuffer(x).toList() as follows:
import scala.collection.JavaConversions;
import java.util.ArrayList;
import java.util.List;
public CardSet buildCardSet(Set<Widget> widgets) {
List<CardDrawn> cardObjects = new ArrayList<>();
for( Widget t : widgets ) {
CardDrawn cd = new CardDrawn(t.player, t.card);
cardObjects.add(cd);
}
CardSet cs = new CardSet(JavaConversions.asScalaBuffer(cardObjects).toList());
return cs;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…