From 5d555ef90f443e20d2e46c668e456df0a643dae8 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 17 Mar 2012 21:12:51 -0700 Subject: Overhaul of JavaConver{sions,ters}. Initially motivated by SI-5580, then just motivated. I broke up the opaquely named JavaConversions and JavaConverters into the following traits encapsulating some permutation of { to java, to scala, bidirectional } { wrappers, decorators } I named everything consistently in terms of either Wrappers or Decorators. Decorators install those asJava/asScala methods onto collections of the right kind; Wrappers hide the process. JavaConversions then reduces to an object which (ill-advisedly) extends both WrapAsJava and WrapAsScala. And JavaConverters is an object extending DecorateAsScala and DecorateAsJava. However other more clearly named vals exist in the newly created scala.collection.convert package object. val decorateAsJava = new DecorateAsJava { } val decorateAsScala = new DecorateAsScala { } val decorateAll = new DecorateAsJava with DecorateAsScala { } val wrapAsJava = new WrapAsJava { } val wrapAsScala = new WrapAsScala { } val wrapAll = new WrapAsJava with WrapAsScala { } So for instance to import asScala decorators, and only those: scala> import scala.collection.convert.decorateAsScala._ import scala.collection.convert.decorateAsScala._ scala> new java.util.ArrayList[String].asScala groupBy (x => x) res0: scala.collection.immutable.Map[String,scala.collection.mutable.Buffer[String]] = Map() I propose we put those vals or a subset of them in the scala package object rather than way down in scala.collection.convert. --- test/files/pos/t5580b.scala | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/files/pos/t5580b.scala (limited to 'test/files/pos') diff --git a/test/files/pos/t5580b.scala b/test/files/pos/t5580b.scala new file mode 100644 index 0000000000..d5a4a0a2b2 --- /dev/null +++ b/test/files/pos/t5580b.scala @@ -0,0 +1,19 @@ +/** It's a pos test because it does indeed compile, + * not so much because I'm glad it does. Testing + * that error messages created and discarded during + * implicit search don't blow it up. + */ + +import scala.collection.mutable.WeakHashMap +import scala.collection.JavaConversions._ + +class bar { } + +class foo { + val map = WeakHashMap[AnyRef, collection.mutable.Map[bar, collection.mutable.Set[bar]]]() + + def test={ + val tmp:bar=null + if (map.get(tmp).isEmpty) map.put(tmp,collection.mutable.Set()) + } +} -- cgit v1.2.3