In the above code the compilation fails. I cannot explain. The method in the concrete implementation is a valid override and the return type is an int which can easily be autoboxed into an Integer . Can anyone explain why the compilation fails?
An overriding method can have the same return type as the method it overrides, or a covariant return, which means it can also have a subtype. Even though in many cases the compiler will autobox an int to Integer, they are definitely not the same return type, and this override doesn't follow the contract.
Just think, the method returning an int will in many cases behave differently than the method returning an Integer (i.e. widening). So it is only logical that the compiler doesn't let you do this.