You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
scala> scala.util.control.Exception.catching(classOf[ClassNotFoundException]).opt(Class.forName(""))
<console>:8:error: typemismatch;
found : java.lang.Class[_]
required: java.lang.Class[?0(in value res0)] where type?0(in value res0)
Note:Any>:?0, but Java-defined classClass is invariant in typeT.
You may wish to investigate a wildcard typesuch as `_ >: ?0`. (SLS3.2.10)
scala.util.control.Exception.catching(classOf[ClassNotFoundException]).opt(Class.forName(""))
^
If I set the type parameter explicitly, it compiles:
@adriaanm said:
I agree it would be nice to improve this. Sometimes you just have to add a type parameter, as type inference is limited. Avoid existential types whenever possible.
scala-hash v2.10.2~15 -nc -e 'scala.util.control.Exception.catching(classOf[ClassNotFoundException]).opt(Class.forName(""))'
[info] downloading http://scala-webapps.epfl.ch/artifacts/70e2ead142f87ebd5f4c6859ce17c72fdff8bd3b/pack.tgz ...done.
[info] scala revision from 2013-05-15 15:59:12 -0700 downloaded to /Users/jason/usr/scala-v2.10.1-318-g70e2ead
/var/folders/s2/g6fgtpk52hl8njjvx8vyzr9r0000gn/T/scalacmd861028181716928737.scala:1: error: type mismatch;
found : Class[_]
required: Class[?0(in value <local $anon>)] where type ?0(in value <local $anon>)
Note: Any >: ?0, but Java-defined class Class is invariant in type T.
You may wish to investigate a wildcard type such as `_ >: ?0`. (SLS 3.2.10)
scala.util.control.Exception.catching(classOf[ClassNotFoundException]).opt(Class.forName(""))
^
~/code/scala scala-hash v2.10.2~14 -nc -e 'scala.util.control.Exception.catching(classOf[ClassNotFoundException]).opt(Class.forName(""))'
If I set the type parameter explicitly, it compiles:
The text was updated successfully, but these errors were encountered: