4

I have been struggling with functional programming concepts for a while. I read that in functional programming, variable immutability is a fundamental thing. You don't change the state of a variable.

But I can achieve the same effect in Java by using the keyword 'final'? So why cannot Java be used as a functional language?

gnat
  • 20,543
  • 29
  • 115
  • 306
Kaushik
  • 1,205

1 Answers1

4

Sure, you can do programming in a functional style in Java. It's just really difficult, because there's a lot more to it than just immutability. One of the big ones is first-class functions, (being able to treat a function reference as a variable, without it having to be tied to an object,) which the Java language has provided no functionality for up until very recently, when lambdas were introduced.

Even now that it's possible, there's still 20 years of legacy Java code hanging around that has no concept of functional programming, that your code will probably have to interact with, so that makes any use of it more difficult than it probably should be.

Mason Wheeler
  • 83,213