3 ms·
I've been using Java 21 for Advent of Code this year, and I've been surprised at how much less clunky it is than I remember. `var` and `record`'s are especially
by losvedir 2y ago
I've been using Java 21 for Advent of Code this year, and I've been surprised at how much less clunky it is than I remember. `var` and `record`'s are especially nice for how I like to code. It's still not perfect, but it's not something that I hate programming in now.
These were some neat tricks. I've been using the `java myfile.java` approach for running the AoC problems. I didn't realize the "implicit class" thing where you could have top level statements and methods, though, with the automatic import of java.base. That's pretty slick for this.
- papercrane 2y agoRecords being allowed in methods has been great for me when doing things like path finding. Makes it easy to write something like: record Node(int cost, int row, int col){} var pq = new PriorityQueue<Node>(Comparator.comparingInt(Node::cost));
- gf000 2y agoThis is actually a natural extension of classes being allowed inside, which is not well-known for some reason. Nonetheless, I also really like this feature with records.
- roncesvalles 2y agoIt's allowed because Record automatically implements methods called cost(), row(), and col().
- user_of_the_wek 2y agoJust to be clear, the implicit class thing is still a preview feature as of Java 24, which should come out next March. It might be finalized for Java 25, in the coming September. But no guarantees. Until then you'd need to explicitly enable it with a cli parameter.
- ansgri 2y agoSo it’s almost as good as C#? Which would be my favorite language if not for strong ties to MS ecosystem.
- deleted 2y ago[deleted]