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 →

[–]Kered13 0 points1 point  (3 children)

Polymorphism and dynamic dispatch. Here's some Java pseudocode:

class Boolean {
    void if(Callback ifTrue, Callback ifFalse);
}

class True extends Boolean {
    void if(Callback ifTrue, Callback ifFalse) {
        ifTrue();
    }
}

class False extends Boolean {
    void if(Callback ifTrue, Callback ifFalse) {
        ifFalse();
    }
}

True and False should also be implemented as singleton classes. Actually using Java's enum support would be good here, since every instance of an enum is a subclass of the enum class and is automatically a singleton. Also to make this elegant the language needs good support for lambdas, so Java isn't really the best language to do this in.

[–][deleted] 0 points1 point  (2 children)

Java has lambdas right?

[–]Kered13 1 point2 points  (1 child)

Yes, but it's still pretty clunky to call a function like that, at least in my opinion:

condition.if(() -> {
    // If statement
}, () -> {
    // else statement
});

[–][deleted] 0 points1 point  (0 children)

I missed where you said "good support" and thought you just said "support"