-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
[MNG-8014] Fix multithreaded builder #1386
Conversation
import java.util.function.Predicate; | ||
import java.util.function.UnaryOperator; | ||
|
||
class ImmutableCollections { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why? Why over Collections?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same classes are used in the immutable classes generated from the modello schemas.
Those are similar to the new Map.of()
and List.of()
in recent JDKs.
The main benefit is that there's no copy if you ask for an immutable collection if you pass an already immutable collection (this list is always wrapped in JDK 8) and there's no safe copy, i.e. the unmodifiable collection is just a wrapper on top of the collection, so it's still can be modified, so one needs to do a copy first.
Bottom line, the current code is actually using Collections.unmodifiableMap(new HashMap<>(attributes))
which is quite expensive.
If we were to raise the runtime requirement to JDK 9, I'd happily get rid of those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.