Re: Sammy + wildcards + type inference = :(
Roman Janusz <[email protected]>
| Newsgroups | gmane.comp.lang.scala |
|---|---|
| Message-ID | <[email protected]> |
Not much of an improvement if I can't chain:
scala> new
java.util.ArrayList[String]().stream.map(_.toInt).map(_.toString):
JStream[String]
<console>:9: error: no type parameters for method map: (x$1:
java.util.function.Function[_ >: String, _ <: R])java.util.stream.Stream[R]
exist so that it can be applied to arguments
(java.util.function.Function[String,Int] with Serializable)
--- because ---
argument expression's type is not compatible with formal parameter type;
found : java.util.function.Function[String,Int] with Serializable
required: java.util.function.Function[_ >: String, _ <: ?R]
Note: String <: Any (and java.util.function.Function[String,Int] with
Serializable <: java.util.function.Function[String,Int]), but Java-defined
trait Function is invariant in type T.
You may wish to investigate a wildcard type such as `_ <: Any`. (SLS 3.2.10)
new
java.util.ArrayList[String]().stream.map(_.toInt).map(_.toString):
JStream[String]
^
<console>:9: error: type mismatch;
found : java.util.function.Function[String,Int] with Serializable
required: java.util.function.Function[_ >: String, _ <: R]
new
java.util.ArrayList[String]().stream.map(_.toInt).map(_.toString):
JStream[String]
W dniu sobota, 27 czerwca 2015 03:37:48 UTC+2 użytkownik Stephen Compall
napisał:
>
> On Fri, 2015-06-26 at 18:05 -0700, Roman Janusz wrote:
>
> Is there any chance this will work?
>
> $ scala -Xexperimental
> Welcome to Scala version 2.11.6 (Java HotSpot(TM) 64-Bit Server VM, Java
> 1.8.0_40).
> Type in expressions to have them evaluated.
> Type :help for more information.
>
> scala> new java.util.ArrayList[String]().stream.map(_.toInt)
> <console>:8: error: no type parameters for method map: (x$1: java.util.
> function.Function[_ >: String, _ <: R])java.util.stream.Stream[R] exist
> so that it can be applied to arguments (java.util.function.Function[String
> ,Int] with Serializable)
> --- because ---
> argument expression's type is not compatible with formal parameter type;
> found : java.util.function.Function[String,Int] with Serializable
> required: java.util.function.Function[_ >: String, _ <: ?R]
>
>
> Not fatal, I would say.
>
> Welcome to Scala version 2.11.7 (OpenJDK 64-Bit Server VM, Java 1.8.0_45).
> Type in expressions to have them evaluated.
> Type :help for more information.
>
> scala> import java.util.ArrayList, java.util.stream.{Stream => JStream}
> import java.util.ArrayList
> import java.util.stream.{Stream=>JStream}
>
> scala> new java.util.ArrayList[String]().stream.map[Int](_.toInt)
> res1: java.util.stream.Stream[Int] = java.util.stream.ReferencePipeline$3...@5b49c202 <javascript:>
>
> scala> new java.util.ArrayList[String]().stream.map(_.toInt): JStream[Int]
> res2: java.util.stream.Stream[Int] = java.util.stream.ReferencePipeline$3...@47bded3c <javascript:>
>
>
> Not ideal, but maybe something else is going on here.
>
> --
> Stephen Compall
> "^aCollection allSatisfy: [:each|aCondition]": less is better
>
>
--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.