In particular an immutable List with a cons operation would be wel开发者_JS百科come.
Dug around a little bit longer. This library probably comes closest: http://functionaljava.googlecode.com/svn/artifacts/2.22/javadoc/index.html . I would imagine that it would be possible to use Clojure's collection classes directly, but I'm not sure if would feel all that natural. (And I don't necessarily need to 'transactional' behaviour.)
There's also a project of "Clojure's data structures modified for use outside of Clojure" at: https://github.com/krukow/clj-ds
I've written a bunch of persistent data structures in Java. My "PersistentList" is pretty close to what you want.
http://code.google.com/p/mikeralib/source/browse/trunk/Mikera/src/mikera/persistent/PersistentList.java
There are multiple solutions posted in Cons’ing a List in Java. And immutability can be added with:
List l;
...
l = Collections.unmodifiableList(l);
I'm currently using Google Guava. Its collections package has immutable variants for lists, maps, sets, amongst others. The code is easy to use and of high quality.
However, because of implementation details, efficiently consing to a list might not be possible.
精彩评论