I wonder why does this piece of code compile successfully?
Source code:
abstract class A
{
public abstract A s
Adding
to the first example doesn't add anything the compiler cares about. Remember you are saying "a type which is a supertype of M" if we are saying "M is a subtype of Number" and "the type is a supertype of M", we aren't actually saying if the type is a subtype of Number.
For a better example, have M
be Integer
and the variable be of type A
. While obviously that won't work, it satisfies all the requirements of the function correctly.
Since there exists no way to fix the function definition, it just lets it pass and assumes the call site will catch the problem.