<div dir="ltr">Hi,<div><br></div><div>I have read JEP 300, and it seems it is not defining what it intends to do with casting these adjusted types to a subtype. For example consider the following method:</div><div><br></div><div>```</div><div><T> void method1(Iterable<T> itr) {</div><div>Â if (itr instanceof List) {</div><div>Â Â var list = (List<T>) itr;</div><div>Â Â list.add(null);</div><div>Â }</div><div>}</div><div>```</div><div><br></div><div>The cast in the above example is safe (it doesn't emit any unsafe cast warning). However, if `Iterable` becomes covariant at the declaration site, then the above code is now unsafe.</div><div><br></div><div>What is the plan of the JEP with such casting? Will it make the above cast unsafe? If so, then there will be no way to safely cast from `Iterable<T>` to `List<T>`. Admittedly, I can't recall any code I have ever seen where this would be a problem (and so I wouldn't worry about it too much), but it would be nice if the JEP would explicitly address this question.</div><div><br></div><div>In Kotlin, they allow such unsafe casts without a warning (in fact, you don't even need a cast in Kotlin for it). For example, the following code compiles without warning in Kotlin:</div><div><br></div><div>```</div><div>fun evilMethod(list: List<Any>) {<br>Â if (list is MutableList) {<br>Â Â list.add("hello")<br>Â }<br>}</div><div><br></div><div>fun naiveMethod() {<br>Â val list = mutableListOf<Int>()<br>Â evilMethod(list)<br>Â println(list.sum())<br>}</div><div>```</div><div><br></div><div>Of course, calling `naiveMethod` fails with an exception when trying to call `sum`. (Note: `List` in Kotlin is a "read-only" variant of Java's List, and MutableList is the equivalent of Java's List interface).</div><div><br></div><div>I personally don't like the behavior of Kotlin, and would rather choose that only `Iterable<T>` to `List<? extends T>` is safe from here onwards.</div><div><br></div><div>Attila</div><div><br></div></div>