简体   繁体   中英

Using the Scala collections (immutable) from Java

Is it possible to use the Scala immutable collections (HashMap, List, Vector, etc.) from Java code? I realize that some of the method names may end up looking "funny" and contain "$".

I have a legacy application written in Java. I cannot convert the code at this time, but I would like to use the immutable data structures to improve concurrency (multiple reads for every write).

Yes, you just need to put scala-library.jar in the classpath. See this thread for an example using Scala immutable lists in Java

As an alternative, Clojure also offers persistent data structures eg a PersistentHashMap that come with Java source code, so your method names won't look as odd

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM