This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-03-03
Channels
- # ai (1)
- # announcements (1)
- # beginners (5)
- # biff (23)
- # clojure (3)
- # clojure-europe (4)
- # clojure-norway (22)
- # clojurescript (21)
- # data-science (1)
- # datascript (5)
- # graalvm (2)
- # gratitude (2)
- # humbleui (4)
- # hyperfiddle (10)
- # lsp (46)
- # off-topic (15)
- # pedestal (1)
- # reitit (3)
- # shadow-cljs (12)
- # sql (4)
Does anyone know why Java doesn't have immutable persistent collections like Clojure or Scala. I know there are some libs but they seem to loose traction and end up not being maintained. So many improvements to Java and this is never thought of? Strange to me. Any thoughts? Thanks in advance
Isn't Java Data Classes a java take on immutability ?
The Java language architect at Oracle keynoted Clojure/conj a few years ago. They're very well aware!
Brian Göetz, Java concurrency in practice, has a section 3.4 on immutability. Clojure is his preferred JVM language https://www.youtube.com/watch?v=GedrGWu16_I
1. Java's language strategy is to not force a gazillion LOC migration efforts (for instance as in javascript libraries or python 2 -> python 3). It would bring a lot of confusion if the old Collection API would be deprecated or be placed onto the brink of deprecation. So I think this is also avoided. 2. There are https://github.com/search?q=persistent+data+structures+language%3AJava&type=repositories&l=Java that implement persistent data structures and it actually doesn't need to be solved in the language (insert the famous foreach quote here where the compiler author has to intervene to support this syntax and individual developer is always faster to implement it themselves)
java.util.collection
APIs have a lot void
methods all over it.
There are unmodifiable implementations of those interfaces which throw if you call mutating methods, and there are streams. That covers a lot use cases. Adding additional methods (if possible, e.g. default
) or new interfaces would just confuse users I think.
There’s plenty of async frameworks, and they still decided to implement virtual threads. They could decide that a standardised set of immutable data structures would be valuable to have in core.
A lot of design decisions in project Loom is about the good integration of virtual threads with existing APIs.
Ok, not with CompletableFuture, but many others.
@U05C4RCR8BT There is a good deal of background discussion on it. If you watch some talks on the collections framework persistent collections is brought up as one of the few reasons they might consider a collections 2.0
so its been thought of, just prioritized kinda low compared to other stuff and its uncertain whether they should be in the stdlib
but there is the https://www.vavr.io/ library, which gives ~ the same API as the scala stdlib