Why can static methods in an interface in java 8 not be declared as final? What would the difference be by adding final?
Asked
Active
Viewed 64 times
0
-
Can you post an example of what's working and what's not? I don't fully get what you are asking... – deHaar Aug 08 '19 at 10:17
-
3They can be `static` since Java 9. Also making `static` methods `final` in interface is pointless since they are not inherited, for instance we can't use `List.of(...)` via `ArrayList.of(...)`. – Pshemo Aug 08 '19 at 10:18
-
2@Pshemo interfaces allow `static` method since Java 8. The `private` methods are new in Java 9. – Holger Aug 08 '19 at 18:19
-
@Holger Woops, thank you for correction. I somehow connected it with introduction of collections factory methods like `List.of` but somehow forgot about many other static methods introduced with streams like `Comparator.comparing(...)`. Unfortunately I can't correct my previous comment so at least will upvote yours for better visibility. Again thank you. – Pshemo Aug 08 '19 at 19:53
-
@Pshemo well, the main point of your comment still is correct, `static` interface methods are not inherited, so `final` would be meaningless. – Holger Aug 09 '19 at 07:04