OnJava8-Examples/interfaces/CheckedDowncast.java
2021-09-20 17:33:35 -06:00

20 lines
521 B
Java

// interfaces/CheckedDowncast.java
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// {NewFeature} Since JDK 17
sealed interface II permits JJ {}
final class JJ implements II {}
class Something {}
public class CheckedDowncast {
public void f() {
II i = new JJ();
JJ j = (JJ)i;
// Something s = (Something)i;
// error: incompatible types: II cannot
// be converted to Something
}
}