Skip to content

Instantly share code, notes, and snippets.

@themel
Created March 12, 2013 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save themel/5141394 to your computer and use it in GitHub Desktop.
Save themel/5141394 to your computer and use it in GitHub Desktop.
Scala is weird.
C:\Program Files\scala\bin>scala
Welcome to Scala version 2.10.0 (Java HotSpot(TM) Client VM, Java 1.6.0_14).
Type in expressions to have them evaluated.
Type :help for more information.
scala> val s: Seq[Class[_ <: java.lang.Enum[_]]] = Seq(classOf[java.util.concurrent.TimeUnit], classOf[javax.lang.model.SourceVersion])
s: Seq[Class[_ <: Enum[_]]] = List(class java.util.concurrent.TimeUnit, class javax.lang.model.SourceVersion)
scala> s.flatMap(_.getEnumConstants)
<console>:9: error: no type parameters for method flatMap: (f: Class[_ <: Enum[_]] => scala.collection.GenTraversableOnce[B])(implicit bf: scala.collection.generic.CanBuildFrom[Seq[Class[_ <: Enum[_]]],B,That])That exist so that it can be applied to arguments (Class[_ <: Enum[_]] => scala.collection.mutable.ArrayOps[(some other)_$1(in object $iw) with Object] forSome { type (some other)_$1(in object $iw) <: Enum[_] })
--- because ---
argument expression's type is not compatible with formal parameter type;
found : Class[_ <: Enum[_]] => scala.collection.mutable.ArrayOps[(some other)_$1(in object $iw) with Object] forSome { type (some other)_$1(in object $iw) <: Enum[_] }
required: Class[_ <: Enum[_]] => scala.collection.GenTraversableOnce[?B]
s.flatMap(_.getEnumConstants)
^
<console>:9: error: type mismatch;
found : Class[_ <: Enum[_]] => scala.collection.mutable.ArrayOps[(some other)_$1(in object $iw) with Object] forSome { type (some other)_$1(in object $iw) <: Enum[_] }
required: Class[_ <: Enum[_]] => scala.collection.GenTraversableOnce[B]
s.flatMap(_.getEnumConstants)
^
<console>:9: error: Cannot construct a collection of type That with elements of type B based on a collection of type Seq[Class[_ <: Enum[_]]].
s.flatMap(_.getEnumConstants)
^
scala> s.flatMap(_.getEnumConstants.toSeq)
res1: Seq[Enum[_]] = List(NANOSECONDS, MICROSECONDS, MILLISECONDS, SECONDS, MINUTES, HOURS, DAYS, RELEASE_0, RELEASE_1, RELEASE_2, RELEASE_3, RELEASE_4, RELEASE_5, RELEASE_6)
scala> s.flatMap(_.getEnumConstants.toArray)
<console>:9: error: polymorphic expression cannot be instantiated to expected type;
found : [U >: _$1 with Object]Array[U]
required: scala.collection.GenTraversableOnce[?]
s.flatMap(_.getEnumConstants.toArray)
^
error: type mismatch;
found : Array[?U]
required: scala.collection.GenTraversableOnce[?]
Note that implicit conversions are not applicable because they are ambiguous:
both method booleanArrayOps in object Predef of type (xs: Array[Boolean])scala.collection.mutable.ArrayOps[Boolean]
and method byteArrayOps in object Predef of type (xs: Array[Byte])scala.collection.mutable.ArrayOps[Byte]
are possible conversion functions from Array[?U] to scala.collection.GenTraversableOnce[?]
error: type mismatch;
found : Array[?U]
required: scala.collection.GenTraversableOnce[?]
Note that implicit conversions are not applicable because they are ambiguous:
both method booleanArrayOps in object Predef of type (xs: Array[Boolean])scala.collection.mutable.ArrayOps[Boolean]
and method byteArrayOps in object Predef of type (xs: Array[Byte])scala.collection.mutable.ArrayOps[Byte]
are possible conversion functions from Array[?U] to scala.collection.GenTraversableOnce[?]
error: type mismatch;
found : Array[?U]
required: scala.collection.GenTraversableOnce[?]
Note that implicit conversions are not applicable because they are ambiguous:
both method booleanArrayOps in object Predef of type (xs: Array[Boolean])scala.collection.mutable.ArrayOps[Boolean]
and method byteArrayOps in object Predef of type (xs: Array[Byte])scala.collection.mutable.ArrayOps[Byte]
are possible conversion functions from Array[?U] to scala.collection.GenTraversableOnce[?]
scala> s.flatMap(_.getEnumConstants.toSeq)
error: type mismatch;
found : Array[?U]
required: scala.collection.GenTraversableOnce[?]
Note that implicit conversions are not applicable because they are ambiguous:
both method booleanArrayOps in object Predef of type (xs: Array[Boolean])scala.collection.mutable.ArrayOps[Boolean]
and method byteArrayOps in object Predef of type (xs: Array[Byte])scala.collection.mutable.ArrayOps[Byte]
are possible conversion functions from Array[?U] to scala.collection.GenTraversableOnce[?]
error: type mismatch;
found : Array[?U]
required: scala.collection.GenTraversableOnce[?]
Note that implicit conversions are not applicable because they are ambiguous:
both method booleanArrayOps in object Predef of type (xs: Array[Boolean])scala.collection.mutable.ArrayOps[Boolean]
and method byteArrayOps in object Predef of type (xs: Array[Byte])scala.collection.mutable.ArrayOps[Byte]
are possible conversion functions from Array[?U] to scala.collection.GenTraversableOnce[?]
error: type mismatch;
found : Array[?U]
required: scala.collection.GenTraversableOnce[?]
Note that implicit conversions are not applicable because they are ambiguous:
both method booleanArrayOps in object Predef of type (xs: Array[Boolean])scala.collection.mutable.ArrayOps[Boolean]
and method byteArrayOps in object Predef of type (xs: Array[Byte])scala.collection.mutable.ArrayOps[Byte]
are possible conversion functions from Array[?U] to scala.collection.GenTraversableOnce[?]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment