In java 8, why cannot call the interface static method that the current class is implementing [duplicate]

Addition of static methods in interface in Java 8 came with 1 restriction – those methods cannot be inherited by the class implementing it. And that makes sense, as a class can implement multiple interface. And if 2 interfaces have same static method, they both would be inherited, and compiler wouldn’t know which one to invoke.

However, with extending class, that’s no issue. static class methods are inherited by subclass.

See JLS §8.4.8:

A class C inherits from its direct superclass all concrete methods m (both static and instance) of the superclass

A class C inherits from its direct superclass and direct superinterfaces all abstract and default (§9.4) methods m

A class does not inherit static methods from its superinterfaces.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)