Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Towards member patterns [Brian Goetz] (openjdk.org)
3 points by kaba0 on Jan 23, 2024 | hide | past | favorite | 1 comment


The new Match<IN, COND_OUT> is one of my favorite parts of this proposal. It really makes patterns feel like a first-class citizen rather than just a weird amalgamation of a method. Now, it feels like almost anything that we can do with a method, we can do the inverse of with a pattern. Especially the pattern lambdas and pattern references!

What place do getters have in this new world of pattern-matching? The doc points out how methods in general still have value (functions that are not really inverse-able), but getters specifically? It kind of seems like there isn't really any more value in them. How do other languages who have had PM for longer use their getters? Or does PM just not overtake getters there like it looks like it will here?

Maybe getters can be seen as just another unconditional pattern, where it always matches. But in that case, it seems like a PM gives you all the capabilities of getters with a little more safety and flexibility. So in that case, again, why have normal getters? I won't go back and undo all my old code, but I'm starting to think I won't need to write any new getters ever again. (Unless I'm touching legacy code)




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

Search: