Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Not really the precise answer, but two observations - Scala 2.10 will give you a nicer error:</p> <pre><code>scala&gt; s.flatMap(_.getEnumConstants) &lt;console&gt;:9: error: no type parameters for method flatMap: (f: Class[_ &lt;: Enum[_]] =&gt; scala.collection.GenTraversableOnce[B])(implicit bf: scala.collection.generic.CanBuildFrom[Seq[Class[_ &lt;: Enum[_]]],B,That])That exist so that it can be applied to arguments (Class[_ &lt;: Enum[_]] =&gt; scala.collection.mutable.ArrayOps[(some other)_$1(in object $iw) with Object] forSome { type (some other)_$1(in object $iw) &lt;: Enum[_] }) --- because --- argument expression's type is not compatible with formal parameter type; found : Class[_ &lt;: Enum[_]] =&gt; scala.collection.mutable.ArrayOps[(some other)_$1(in object $iw) with Object] forSome { type (some other)_$1(in object $iw) &lt;: Enum[_] } required: Class[_ &lt;: Enum[_]] =&gt; scala.collection.GenTraversableOnce[?B] s.flatMap(_.getEnumConstants) ^ &lt;console&gt;:9: error: type mismatch; found : Class[_ &lt;: Enum[_]] =&gt; scala.collection.mutable.ArrayOps[(some other)_$1(in object $iw) with Object] forSome { type (some other)_$1(in object $iw) &lt;: Enum[_] } required: Class[_ &lt;: Enum[_]] =&gt; scala.collection.GenTraversableOnce[B] s.flatMap(_.getEnumConstants) ^ &lt;console&gt;:9: error: Cannot construct a collection of type That with elements of type B based on a collection of type Seq[Class[_ &lt;: Enum[_]]]. s.flatMap(_.getEnumConstants) ^ </code></pre> <p>And, if you split your <code>flatMap</code>, you get to see a simpler version of the issue:</p> <pre><code>scala&gt; s.map(_.getEnumConstants) res28: Seq[Array[_$1 with Object] forSome { type _$1 &lt;: Enum[_] }] = List(Array(NANOSECONDS, MICROSECONDS, MILLISECONDS, SECONDS, MINUTES, HOURS, DAYS), Array(RELEASE_0, RELEASE_1, RELEASE_2, RELEASE_3, RELEASE_4, RELEASE_5, RELEASE_6)) scala&gt; res28.flatten &lt;console&gt;:10: error: No implicit view available from Array[_$1 with Object] forSome { type _$1 &lt;: Enum[_] } =&gt; scala.collection.GenTraversableOnce[B]. res28.flatten ^ </code></pre> <p>That is rather surprising since you'd think that it should be easy to turn an <code>Array</code> into a <code>GenTraversableOnce</code>. I don't have time to dig out the details at the moment, but I'll point out that the following things seem to work:</p> <pre><code>s.flatMap(_.getEnumConstants.toSeq) s.flatMap(_.getEnumConstants.map(_.asInstanceOf[Enum[_]])) </code></pre> <p>I vote compiler bug, because of <a href="https://gist.github.com/themel/5141394" rel="nofollow">this gist</a>, which shows some very weird behaviour in the REPL for this simple script</p> <pre><code>val s: Seq[Class[_ &lt;: java.lang.Enum[_]]] = Seq(classOf[java.util.concurrent.TimeUnit], classOf[javax.lang.model.SourceVersion]) s.flatMap(_.getEnumConstants.toSeq) s.flatMap(_.getEnumConstants.toArray) 1234 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload