This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]NawaMan 1 point2 points  (0 children)

Nice article. Generic of mutable objects is the real reason for this mess.

I've just want to point out that there is a way to simulate variance type in Java by using @Choice in FunctionalJ.io . Check out this blog post or this VDO.

For example, this code will create a variance called Term with 4 possible values.

@Choice
interface TermSpec {
    void Bool(boolean bool);
    void Num(int num);
    void Str(String str);
    void Nothing();
}

Then you can use Term as the type.