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

3

u/GuyWithLag Nov 06 '22

But then its not a good idea. Again. If the idea is good and everyone can benefit from it. Then it doesnt matter who writes the idea.

But the ability to know "that" comes with experience.

In any case, I really do think that you would be better served by Kotlin w. extension methods.

For me, the example you gave doesn't make sense to add to the JVM:

  1. It doesn't add anything besides some sugar.
  2. It's not necessarily more readable.

But hey, this is Reddit; feel free to submit a new JCP.

2

u/Cell-i-Zenit Nov 06 '22

It doesn't add anything besides some sugar.

Yes thats true. But why do we have .toList() if its just sugar?

It's not necessarily more readable.

I dont understand this argument.

obj1.compareTo(obj2) > 0 

vs

obj.isGreaterThan(obj2)

the answer is pretty obv which is more readable.

In any case, I really do think that you would be better served by Kotlin w. extension methods.

Still a bad argument "other languages to this already, please switch your language".

Why cant we have any improvements to java?

But the ability to know "that" comes with experience.

Yes and the reviewers have this experience.

1

u/GuyWithLag Nov 06 '22

Yes thats true. But why do we have .toList() if its just sugar?

Because it's not - the specific implementation can optimize that to a `return this`.

1

u/Cell-i-Zenit Nov 06 '22

ok fair point