views:

362

answers:

5
+6  Q: 

immutable java

immutability, any good sources on writing immutable programs in a functional way with java?

shifting over to erlang - scala - clojure is not a possibility.

+5  A: 

Java Concurrency in Practice has lots of good information about immutability. Basically you can write functionally (without regard to state) if you're not sharing state between invocations, write your state immutably, or write statelessly. Can you post something more specific about what you're trying to accomplish?

Steve B.
Man, I don't think I've ever seen a technical book on Amazon with that many great ratings...
John Munsch
Steve, Erlang my moonlighter, is a heavy inspiration for me. I simply wish to adjust my Java coding habits - that is all.
Setori
+2  A: 

besides Java Concurrency in Practice, there also several good items in Effective Java (second edition)

dfa
A: 

Libraries like: Functional Java and lambdaj - and some others. Looks like this is a common requirement.

mparaz
The lambdaj library is really cool. Unfortunately, it's also really slow, from the tests I ran... approx 10x slower on the data sets I tested on. Shame, because I was very excited about it.
RHSeeger
+2  A: 

One thing to be careful of is if you use existing JVM libraries they may have nasties hidding inside - like use non-thread safe static variables. I think functional programming for concurrency is a great direction, but I think Erlang will always have the benefit of being designed for functional programming from the ground up. I think Scala will be big here, but suffer from the inability to guarantee isolatation of Actors (you cannot guarantee no mutable shared memory between actors/threads).

Alan Kent