Persistent data structures in Java

前端 未结 8 1486
轻奢々
轻奢々 2021-01-30 02:54

Does anyone know a library or some at least some research on creating and using persistent data structures in Java? I don\'t refer to persistence as long term storage but persis

8条回答
  •  野性不改
    2021-01-30 03:15

    Builders will make your code too verbose to be usable. In practice, almost all immutable data structures I've seen pass in state through the constructor. For what its worth, here are a nice series of posts describing immutable data structures in C# (which should convert readily into Java):

    • Part 1: Kinds of Immutability
    • Part 2: Simple Immutable Stack
    • Part 3: Covariant Immutable Stack
    • Part 4: Immutable Queue
    • Part 5: Lolz! (included for completeness)
    • Part 6: Simple Binary Tree
    • Part 7: More on Binary Trees
    • Part 8: Even More on Binary Trees
    • Part 9: AVL Tree Implementation
    • Part 10: Double-ended Queue
    • Part 11: Working Double-ended Queue Implementation

    C# and Java are extremely verbose, so the code in these articles is quite scary. I recommend learning OCaml, F#, or Scala and familiarizing yourself with immutability with those languages. Once you master the technique, you'll be able to apply the same coding style to Java much more easily.

提交回复
热议问题