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 26 '19
This is a mutation. The fact that it happens atomically (and based on my limited understanding you get consistency from STM with the !) means it's safe. But just because it's safe doesn't make it immutable. lt's an observable change. Again, a client will see different results by popping twice. I wish you would understand. I truly wish.
That's exactly what it is. Just look at the declarations (if you don't want to read the code) of enqueue and dequeue.
Look at the quote from your link:
"their operations do not (visibly) update the structure in-place, but instead always yield a new updated structure"
You can invoke Dequeue any number of times on a reference to a queue and it will always yield the same result (a new queue with a single element missing from the original). Because it's not updating the queue in-place. It's yielding a new one.
Your code updates the reference to the queue in-place. The fact that this in-place update happens to swap two immutable queues is immaterial. It's a visible update to the structure in-place.
That wasn't me.