Skip to content

Commit

Permalink
s/Conversions/Converters/ , s//asScala/ (watch that last one, it's a …
Browse files Browse the repository at this point in the history
…doozy)
  • Loading branch information
lahosken committed Feb 12, 2013
1 parent ce43bff commit 5248e22
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions web/coll2.textile
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,13 @@ res56: numbers.type = Map((2,3), (4,1), (1,2))

h2(#java). Life with Java

You can easily move between Java and Scala collection types using a set of implicit conversions that are available in the JavaConversions package.
You can easily move between Java and Scala collection types using conversions that are available in the <a href="http://www.scala-lang.org/api/current/index.html#scala.collection.JavaConverters$">JavaConverters package</a>. It decorates commonly-used Java collections with <code>asScala</code> methods and Scala collections with <code>asJava</code> methods.

<pre>
import scala.collection.JavaConversions._
import scala.collection.JavaConverters._
val sl = new scala.collection.mutable.ListBuffer[Int]
val jl : java.util.List[Int] = sl
val sl2 : scala.collection.mutable.Buffer[Int] = jl
val jl : java.util.List[Int] = sl.asJava
val sl2 : scala.collection.mutable.Buffer[Int] = jl.asScala
assert(sl eq sl2)
</pre>

Expand Down
6 changes: 3 additions & 3 deletions web/concurrency.textile
Original file line number Diff line number Diff line change
Expand Up @@ -379,18 +379,18 @@ If you look at the implementation, you realize that it's simply synchronizing on

h2. Java ConcurrentHashMap

Java comes with a nice thread-safe ConcurrentHashMap. Thankfully, we can use JavaConversions to give us nice Scala semantics.
Java comes with a nice thread-safe ConcurrentHashMap. Thankfully, we can use JavaConverters to give us nice Scala semantics.

In fact, we can seamlessly layer our new, thread-safe InvertedIndex as an extension of the old unsafe one.

<pre>
import java.util.concurrent.ConcurrentHashMap
import scala.collection.JavaConversions._
import scala.collection.JavaConverters._

class ConcurrentInvertedIndex(userMap: collection.mutable.ConcurrentMap[String, User])
extends InvertedIndex(userMap) {

def this() = this(new ConcurrentHashMap[String, User])
def this() = this(new ConcurrentHashMap[String, User] asScala)
}
</pre>

Expand Down

0 comments on commit 5248e22

Please sign in to comment.