3 ms·
It's legitimately fascinating to see the rise of pattern matching, to the point that even Java will have it [1]! Combined with lambdas, this is a different lan
by freedomben 5y ago
It's legitimately fascinating to see the rise of pattern matching, to the point that even Java will have it [1]! Combined with lambdas, this is a different language than the Java 1.5 that I first learned. If you would have told me that this would be valid Java code:
static void testStringOrNull(Object o) {
switch (o) {
case null, String s -> System.out.println("String: " + s);
}
}
I would never have believed you. And while it's not Elixir-level pattern matching, it's not toothless either. This is valid pattern matching code too:
static void testTriangle(Shape s) {
switch (s) {
case Triangle t && (t.calculateArea() > 100) ->
System.out.println("Large triangle");
default ->
System.out.println("A shape, possibly a small triangle");
}
}
[1]: https://openjdk.java.net/jeps/420 https://openjdk.java.net/jeps/420
- Angius 5y agoJava turning more and more into poor man's C# with each release
- azth 5y agoMore like a very reasonable C# that fits in your head :) Even C# programmers are complaining about feature creep. Java's Project Loom will be superior to C#'s async/await.
- deleted 5y ago[deleted]
- deleted 5y ago[deleted]
- shepherdjerred 5y agoEverything since Java 7 has been a pleasure. The language is so much more mature now. The only problem is enterprise companies giving it a bad name, but I guess that's the price you pay for its broad usage.
- freedomben 5y agoDo you think Enterprises will ever give up the mountain of "design patterns" that (IMHO) make Java less desirable to work in? The Enterprise FizzBuzz is funny because of how true it is [1]. [1]: https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpris...
- evacchi 5y agorecord patterns may come as soon as JDK 19 https://openjdk.java.net/jeps/405 https://openjdk.java.net/jeps/405 fingers crossed!