Skip to content
New issue

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

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

Already on GitHub? # to your account

Make toList() immutable to align with JDK 16 toList() #244

Closed
amaembo opened this issue Apr 10, 2021 · 2 comments
Closed

Make toList() immutable to align with JDK 16 toList() #244

amaembo opened this issue Apr 10, 2021 · 2 comments
Assignees
Milestone

Comments

@amaembo
Copy link
Owner

amaembo commented Apr 10, 2021

We have StreamEx.toList() that explicitly specified as returning a mutable collection. However, in JDK 16, Stream.toList() method was added that is explicitly specified as returning an unmodifiable collection. So, since JDK 16, StreamEx violates the Stream interface specification. We need to introduce a breaking change to align them:

  • Create explicit toMutableList() method that returns a mutable list
  • Remove mutability guarantee from toList() specification.
  • Make toList() an alias to toMutableList() by default
  • Add a system property streamex.default.immutable. When it's set to true, toList() starts behaving like toImmutableList(). This way, users can test their code whether it's ready for the subsequent change.
  • Add a notice that in future release, toList() will be aliased to toImmutableList().
  • Bump version to 0.8.0

The same will be done for toSet(). For now, let's keep toMap() as is, as there are too many overloads and changes there would make things even more confusing, and bloated.

Also, the behavior of toListAndThen() and toSetAndThen() is not changed: the collection supplied to the lambda will still be mutable (even though it's not specified).

@msladek
Copy link

msladek commented Oct 19, 2021

Breaking the contract of toList/Set/Map in a single version change could cause major trouble for clients. Please provide a proper migration path:

  1. First introduce toMutableList/Set/Map and hint in the Javadoc of toList/Set/Map that toMutableList/Set/Map should be used instead. Maybe even a deprecation annotation is in order.
  2. For the next major version toList/Set/Map can be redirected to toImmutableList/Set/Map and the Javadoc hint / deprecation annotation can be removed again.

@amaembo amaembo added this to the 0.8.0 milestone Nov 4, 2021
@amaembo
Copy link
Owner Author

amaembo commented Nov 4, 2021

@msladek thank you for the feedback. I updated the issue description according to the current plan.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants