Вопрос

I've been looking into concurrency and it seems functional languages are preferred for concurrency because of immutable variables/states (among other reasons) and there is really no need to lock these variables and states when accessing them concurrently. However, I have a problem with this because a language like java allows you to create immutable variables how is this different from the immutability of variables in a functional language ?

Это было полезно?

Решение

The only real difference is that you don't have to jump through hoops to make things immutable in functional languages; it's automatic. With java, you need to force classes to be non-extendable (by making the class final or all of its constructors private) and make certain that none of your fields can change (either by only using primitive and immutable objects for fields or making copies of them on the way in and out).

But immutability is immutability, no matter what type of language you use.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top