Hi,
While trying to implement a program to copy a graph, I ran into an issue. I
am using record classes to represents the node of the graph. However, I found
out recently that the graph may contain cycles. This presents a problem,
because as I build the records of the nodes, I can't create a cycle.
This sounds like something Lazy Constants (originally Stable Values) might have
helped with. However, looking through the second preview docs, I see that
methods `trySet` have been removed, making it impossible to construct the nodes
with place holders, and then fill them in later. Additionally, the change in
name "Stable Values" to "Lazy Constants" implies they are closer to constants
(in the JLS sense) than final variables. I think this loss of API surface and
name change subtly excludes my use case, sadly.
Secondly, the reason I wanted to make a copy of the graph was to ensure that
the nodes would be serializable. Serialization is better defined for record
classes, so I prefer to use them over regular classes. I saw in the
documentation that. Lazy Constants will not be Serializable, which further
limits my use of them. I would like to ask that a fully set Lazy Constant be
considered Serializable.
The specific use case I have is that I would like to serialize the type of a
variable. The reflect `Type` is an interface with several implementations. I
am only interested in `Class` and `ParameterizedType`. Since these are
interfaces, and I don't control the implementation, I wanted to copy the
transitive types reachable from them. I also need to be able to serialize
these types. Class is already serializable, and I can make my record node
serializable, but only if the components are too. I had hoped that
representing the possibly cyclic nature of ParameterizedType's getters would be
possible with Stable Values (now Lazy Constants).
I would like to ask that the use case of representing graph nodes as record
classes, which I believe was originally not possible, be considered as a
possibility using Lazy Constants.