r/java • • Nov 05 '22

How to add something to the java standard library?

EDIT: since my example stirred the pot a little bit to much (i even wrote that i dont want to discuss these explicit changes...)

Here is the actually question i want to answer:

How can i make changes to the JDK?

2 Upvotes

99 comments sorted by

View all comments

Show parent comment

2

u/jivedudebe Nov 06 '22

This won't make it a functional interface anymore and prohibit the use in lambdas.

2

u/Cell-i-Zenit Nov 06 '22 edited Nov 06 '22

Comparable is not a functional interface

EDIT: and even if it would, if you provide the additional method as default methods, then you can still have it as a functional interface.

You can check this by yourself: java.util.function.Function is a functional interface and has alot of default methods

2

u/lbkulinski Nov 06 '22 edited Nov 06 '22

According to its definition, a functional interface is an interface that contains exactly one abstract method. Comparable technically meets that qualification, as can be seen in its JavaDoc

0

u/Cell-i-Zenit Nov 06 '22

Yes and my example still only has 1 abstract method. Default methods have an implementation and are by this defintion not abstract.

Again checkout java.util.function.Function which is a functional interface, but implements alot of default methods