在java中将元素添加到scala ListBuffer

时间:2014-03-07 18:32:45

标签: java scala scala-java-interop listbuffer

如果可能的话,最简单的方法是从java中向scala ListBuffer添加元素。

这是scala ListBuffer(在scala中)

var newModVersion: ListBuffer[NewModVersionEntry] = new ListBuffer[NewModVersionEntry]()

这就是我要添加的内容(在java中)

XplosionCoreBL.newModVersion().add(new NewModVersionEntry(name, latestVersion, latestMCVersion, isCritical, description));

2 个答案:

答案 0 :(得分:1)

XplosionCoreBL.newModVersion().$plus$eq(new NewModVersionEntry(name, latestVersion, latestMCVersion, isCritical, description));

在Java中,$plus$eq对应+= (append single element) method of ListBuffer

答案 1 :(得分:0)

List<NewModVersionEntry> asJavaList = scala.collection.JavaConversions.bufferAsJavaList(XplosionCoreBL.newModVersion());
asJavaList.add(new NewModVersionEntry(name, latestVersion, latestMCVersion, isCritical, description));