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
Copy file name to clipboardExpand all lines: core-kotlin-modules/core-kotlin-lang-3/src/test/kotlin/com/baeldung/typeCheckAndCasts/TypeCheckAndCastsUnitTest.kt
+30
Original file line number
Diff line number
Diff line change
@@ -21,6 +21,9 @@ fun doubleTheValue(obj: Any): Any =
21
21
else->"Unsupported Type Found"
22
22
}
23
23
24
+
inlinefun <reifiedT> Any.isType() =thisisT
25
+
inlinefun <reifiedT> Any.isTypedList() =thisisList<*> && all { it isT }
26
+
24
27
classTypeCheckAndSmartCastsUnitTest {
25
28
@Test
26
29
fun`given type check functions when pass an object should get expected result`() {
@@ -34,6 +37,33 @@ class TypeCheckAndSmartCastsUnitTest {
34
37
assertThat(isNotString(aLong)).isTrue
35
38
}
36
39
40
+
@Test
41
+
fun`given an object when check type without generic type parameter should get expected exception`() {
42
+
val aStringList:Any=listOf("string1", "string2", "string3")
43
+
// assertThat(aStringList is List<String>).isTrue() // doesn't compile!!
44
+
assertThat(aStringList isList<*>).isTrue
45
+
}
46
+
47
+
@Test
48
+
fun`given generic type check functions when check type with isType() should get expected incorrect result`() {
49
+
val aStringList:Any=listOf("string1", "string2", "string3")
0 commit comments