
Instance methods are preferred over interface default methods. These rules are driven by the following two principles: However, when the supertypes of a class or interface provide multiple default methods with the same signature, the Java compiler follows inheritance rules to resolve the name conflict. Interface MethodsĪbstract methods in interfaces are inherited like instance methods. enter image description here Then I tried to invalidate cache and restart ( IDEA -> File -> Invalide Caches/Restart). The first is Animal, which contains one instance method and one static method:Īs promised, the version of the hidden static method that gets invoked is the one in the superclass, and the version of the overridden instance method that gets invoked is the one in the subclass. Idea errors found: cannot resolve overloaded method map, but map is very common in scala. The version of the hidden static method that gets invoked depends on whether it is invoked from the superclass or the subclass.Ĭonsider an example that contains two classes.The version of the overridden instance method that gets invoked is the one in the subclass.The distinction between hiding a static method and overriding an instance method has important implications: Biggest difference I see in the type tree is that 2.10.6 tried to cook the method parameters while 2.11.8 doesn't: 2.11. If a subclass defines a static method with the same signature as a static method in the superclass, then the method in the subclass hides the one in the superclass. Perhaps indirectly related to SI-6760 but overloaded method had different signature than Object.clone. If, for some reason, the compiler detects that the method does not exist in one of the superclasses, then it will generate an error. When overriding a method, you might want to use the annotation that instructs the compiler that you intend to override a method in the superclass. This subtype is called a covariant return type. An overriding method can also return a subtype of the type returned by the overridden method. The overriding method has the same name, number and type of parameters, and return type as the method that it overrides. The ability of a subclass to override a method allows a class to inherit from a superclass whose behavior is "close enough" and then to modify behavior as needed.

#Scala cannot resolve overloaded method map plus#
An instance method in a subclass with the same signature (name, plus the number and the type of its parameters) and return type as an instance method in the superclass overrides the superclass's method.
