Skip to content

Commit a81111f

Browse files
committed
add classTag test
1 parent 9b41233 commit a81111f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import scala.reflect.ClassTag
2+
3+
object IsInstanceOfClassTag {
4+
def safeCast[T: ClassTag](x: Any): Option[T] = {
5+
x match {
6+
case x: T => Some(x)
7+
case _ => None
8+
}
9+
}
10+
11+
def foo(x: Any): Boolean =
12+
x.isInstanceOf[List[String]] // error
13+
}

0 commit comments

Comments
 (0)