Suppressing @unchecked warning for a higher-kinded existential type

拈花ヽ惹草 提交于 2019-12-05 11:38:56

With pattern matching you can keep the warnings away:

x match {case _: Foo[_] => ???}

It is also a bit less verbose in my opinion. In case you name the case variable (starting with lower case letter or escaped with back quotes, ie. not _ as in the above example before :), you already have an asInstanceOf.

Kind of guessing:

$ scala210 -language:_
Welcome to Scala version 2.10.4 (OpenJDK 64-Bit Server VM, Java 1.7.0_65).
Type in expressions to have them evaluated.
Type :help for more information.

scala> class Foo[F[_]]
defined class Foo

scala> (null: Any).isInstanceOf[(Foo[F] forSome { type F[_] }) @unchecked]
res0: Boolean = false

The pop-up just told me code blocks are not very informative.

Oh, and s/guessing/experimenting.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!