Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I wish they had better examples, so here is one. Suppose you are making a scene graph, and you want to have a visitor and run code based on the type of the nodes in the graph. Well, consider two approaches. The first approach is to use a bunch of ifs and instanceof, but this isn't clean and it is fragile. The second approach is to make an interface that has all the types listed under a handler (void handle(Type1 t), void handle(Type2 t), ...) and then write some boiler plate code to do the dispatch.

This feature aims at the conciseness of first model (instanceof) with the safety of the second approach (i.e. all types are handled).

I would love this feature for my project! ( https://www.adama-platform.com ) since I use Java to implement a programming language.



This is the point, you dont consider the instanceof approach, is just wrong. You already know your types in advance.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: