Skip to content

Commit bb23ad9

Browse files
cpovirkGoogle Java Core Libraries
authored andcommitted
Document tradeoffs between isInstanceOf and as/assertIs.
(in the spirit of ed794aa) See also https://youtrack.jetbrains.com/issue/KT-58802. RELNOTES=n/a PiperOrigin-RevId: 807747391
1 parent ac02aad commit bb23ad9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

core/src/main/java/com/google/common/truth/Subject.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,15 @@ public final void isNotSameInstanceAs(@Nullable Object other) {
289289
}
290290
}
291291

292-
/** Checks that the value under test is an instance of the given class. */
292+
/**
293+
* Checks that the value under test is an instance of the given class.
294+
*
295+
* <p>Kotlin users: A call to {@code assertThat(foo).isInstanceOf(Bar::class.java)} does not
296+
* perform a smart cast on {@code foo}. If you require a smart cast, consider using {@code foo as
297+
* Bar} or {@code assertIs<Bar>(foo)} instead. The tradeoffs are that those will look different
298+
* than any surrounding Truth assertions and that they will produce worse failure messages (for
299+
* example, by not including the actual value, only its type).
300+
*/
293301
public void isInstanceOf(@Nullable Class<?> clazz) {
294302
if (clazz == null) {
295303
failWithoutActual(

0 commit comments

Comments
 (0)