Consider the following clause from JLS: 8.4.8.3.
If the unerased throws clause of m1 does not contain a supertype of each exception type in the throws clause of m2 (adapted, if necessary, to the type parameters of m1), a compile-time unchecked warning occurs.
Clearly - based on the other rules:
- the super class method must throw super-type of all exception types that the overridden class method throws.
- The child exception list cannot have more members than parent.
What can be the example that satisfies the above clause - that leads to unchecked warning - because based on the rules - it will outright lead to Compile time Error.
Here is an example:
Tis not a supertype ofException, so according to the quote, there should be a warning.Subclass.fooactually fulfils the requirements for overriding (see 8.4.8.1). Specifically,Subclass.foohas the same signature as the erasure of the inheritedSuperclass.foo. The inherited method is supposed to throwT, but after erasure, it throwsExceptiontoo.IntelliJ puts a red underline this, as if it were an error, but you can actually still compile and run the code.
Here is what
javacproduces: