question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mention the benefits that immutable collections have over Java9's "Convenience Factory Methods for Collections" feature

See original GitHub issue

Java 9 has just introduced the “Convenience Factory Methods for Collections” feature. As ImmutableList.of() and similar methods in Guava, these factory methods create unmodifiable collections and prohibit null elements. The created collections are serializable if all of their elements are serializable. Please find more details on http://openjdk.java.net/jeps/269.

It’s worth considering to extend the Javadoc of the corresponding Guava classes (ImmutableList, ImmutableMap and ImmutableSet) like it happened in 3afc6e45c39504ece02d14f4a462f65acfa98652 to discourage using the old factory methods in favor of the Java 7 diamond syntax.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
ineuwirthcommented, Oct 16, 2017

Thank you all for sharing your points on this. All of them are completely reasonable.

But in that case I am wondering if it could be possible to extend the Javadoc or https://github.com/google/guava/wiki/ImmutableCollectionsExplained Wiki page to highlight why Java 9 folks should still prefer the immutable collections provided by Guava instead of using the new ones in JDK.

4reactions
kevinb9ncommented, Nov 13, 2017

What about this appended to the “types, not implementations” section?

Expressing the immutability guarantee directly in the type that your code references is a powerful advantage. Although Java 9 offers certain immutable collection factory methods, like {@code Set.of}, we continue to prefer use of our immutable collection classes for this reason.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java 9 Convenience Factory Methods for Collections - Baeldung
A quick and practical guide to creating collections and maps using Java 9 factory methods.
Read more >
JEP 269: Convenience Factory Methods for Collections
Provide static factory methods on the collection interfaces that will create compact, unmodifiable collection instances.
Read more >
What are the benefits of immutable collections in Java 9?
By using these factory methods, we can create unmodifiable list, set and map collection objects to reduce the number of lines of code....
Read more >
Java Convenience Factory Methods for Collections
The JDK 9 has added static factory methods like of() onto basic Collection interfaces, to create unmodifiable collection objects.
Read more >
Immutable Collections with Factory Methods in Java 9
Learn to create immutable collections such as immutable list, immutable set and immutable map using new factory methods in Java 9.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found