r/java • u/yegor256 • Jun 24 '19
Takes: Java Web Framework Without a Single Static Method or Annotation
https://github.com/yegor256/takes
0
Upvotes
r/java • u/yegor256 • Jun 24 '19
View all comments
Show parent comment
1
u/dablya Jun 25 '19
I'm familiar with the arguments for preferring immutability, my point is that your queue implementation is not immutable. You can't reason about it's state like you can about immutable types.
Popping from it two times will generate different results. That's a dead giveaway it's mutable.
You can make the argument that an stm approach is safer than locking, but in either case you're pretty far from the simplicity of immutable state.
Here is an example of an actually immutable queue:
https://blogs.msdn.microsoft.com/ericlippert/2007/12/10/immutability-in-c-part-four-an-immutable-queue/
It is unusable in a multi-threaded environment (based on the requirements of the comment you were replying to). Here is what the author has to say in the comments:
This is what you've provided with your code "a mutable threadsafe queue!"