Ah, interesting. In the spirit of this question, it doesn’t seem like you even need to keep the sptype
value around at all? Just make the struct be parameterized and don’t include any fields that mention the type.
As for Java, my most familiar language is Rust, and Rust even supports that pattern you mentioned, although you wouldn’t keep the type object around like I suggested. I just didn’t know enough Julia to know how to do that. In fact, you’ll find me on the Rust discourse, answering questions like you are doing here.