47

Having the following code:

fun doSomething(): List<String> {

    val test: List<*> = arrayListOf("test1", "test2")

    return test as List<String>
}

Is there some way to suppress the unchecked cast warning that comes up in the last line? I tried to use the standard Java way @SuppressWarnings("unchecked") at the method level, but it didn't work.

mhlz
  • 3,497
  • 2
  • 23
  • 35
  • 2
    `@Suppress("UNCHECKED_CAST")` works well for IDEA 15.0.4. Just press Alt+Enter on highlighted `test as List` and use *"Suppress 'UNCHECKED_CAST' for fun doSomething"* – awesoon Mar 25 '16 at 14:08

1 Answers1

77

Adding @Suppress("UNCHECKED_CAST") (also possible through IDEA's Alt+Enter menu) to any of statement, function, class and file should help.

Before:

enter image description here

After:

enter image description here

mhlz
  • 3,497
  • 2
  • 23
  • 35
hotkey
  • 140,743
  • 39
  • 371
  • 326