Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java 21 language features #4535

Merged
merged 3 commits into from
Jan 6, 2025
Merged

Conversation

holgerfriedrich
Copy link
Member

@holgerfriedrich holgerfriedrich commented Jan 3, 2025

  • use getFirst and getLast methods
  • replace new Locale by Locale.of
  • replace Paths.get by Path.of
  • use ThreadLocalRandom.current().nextDouble()
  • add @ Serial annotations

* use getFirst and getLast methods
* replace new Locale by Locale.of
* replace Paths.get by Path.of
* use ThreadLocalRandom.current().nextDouble()
* add @serial annotations

Signed-off-by: Holger Friedrich <[email protected]>
@holgerfriedrich holgerfriedrich requested a review from a team as a code owner January 3, 2025 18:09
Signed-off-by: Holger Friedrich <[email protected]>
Signed-off-by: Holger Friedrich <[email protected]>
@andrewfg
Copy link
Contributor

andrewfg commented Jan 4, 2025

use getFirst and getLast methods

And maybe also replace list.add(index, ..) with list.addFirst(..) and list.addLast(..) for those special cases index == 0 resp. index == list.size() - 1. Although probably the latter is quite rare in OH since any sane developer would have simply used list.add(..). => WDYT?

@holgerfriedrich
Copy link
Member Author

use getFirst and getLast methods

And maybe also replace list.add(index, ..) with list.addFirst(..) and list.addLast(..) for those special cases index == 0 resp. index == list.size() - 1. Although probably the latter is quite rare in OH since any sane developer would have simply used list.add(..). => WDYT?

This should already be included. I have seen one occurrence in the code, add(0, ...) in PersistenceExtensions.java.

Copy link
Contributor

@andrewfg andrewfg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks very clean. In particular the List.getFirst() calls. => LGTM

I assume you are working on a similar clean up in addons? But probably wait until the current round of fixes backported into 4.3 will have been completed.

@holgerfriedrich
Copy link
Member Author

@andrewfg I have not started work on the add-ons repo. Last time when I introduced the Java 17 features (mainly instanceof patterns), there were a lot of complaints by add-on authors, as they intend to build and release for the previous 4.x release. I had deliberately waited an additional release cycle (so core used Java17 features one release before). We need to discuss how we want to approach this.

Copy link
Member

@kaikreuzer kaikreuzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, many thanks!

@kaikreuzer
Copy link
Member

Wrt add-on repo: Yes, I assume there would be quite some push-back. We should probably wait until 5.0 is released, so that it is easy for maintainers to build 4.x versions of it. It will also help for backporting code to the 4.3.x branch.

@kaikreuzer kaikreuzer merged commit 40d079a into openhab:main Jan 6, 2025
2 checks passed
@kaikreuzer kaikreuzer added this to the 5.0 milestone Jan 6, 2025
@holgerfriedrich holgerfriedrich deleted the pr-java21 branch January 7, 2025 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants