Frage

If it is possible, how would I loop through a ListBuffer from within java. initialization of the ListBuffer (in scala)

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

current smart for loop (in java)

for (VersionCheckHandler.NewModVersionEntry entry : XplosionCoreBL.newModVersions())
War es hilfreich?

Lösung

You can use JavaConversions for that:

import scala.collection.JavaConversions;
//...
for (YourEntryClass entry : JavaConversions.asJavaIterable(yourListBuffer)) {

(I've switched to placeholder types and vars, since otherwise the example would be less readable)

See this answer to an "inverse" question for general info, and this question+answer for an explanation of the design approach taken in the Scala library.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top