Playing devil's advocate here, could this feature make the language more
expressive?

Take for example an API where you'd typically wrap a method call in
try/catch blocks to handle the various "outcomes" e.g. a user login, you'd
maybe have a UserDisabled exception, a UserAlreadyLoggedIn exception, a
UserPasswordIncorrect exception, etc.

With the addition of this syntactic sugar, the method could instead accept
an anonymous class with a onDisabled, onLoggedIn, onPasswordIncorrect
methods.

Perhaps it would also have a performance benefit over cascading through
catch blocks? Though someone else would have to confirm that.

Reply via email to