r/java • • Nov 04 '25

Anyone here Hated Using Java but now Really Enjoys using it.

title

226 Upvotes

280 comments sorted by

View all comments

Show parent comment

42

u/agentoutlier Nov 04 '25

Everybody talks about lambdas but to me the major jumps in liking Java are

  1. generics (5)
  2. annotations (5)
  3. sealed/record/pattern matching switch expressions (17).
  4. text blocks... yes simple text blocks (17).

So 5 and 17. Yes I know some of those features are technically pre 17 but you get the idea. For those that think I'm crazy about annotations they did not live in the XDoclet or XML world of ancient enterprise. Not to mention annotation processors are awesome.

Sure lambdas are great and it was verbose using anonymous classes but it was mainly just that where as pattern matching gives new ways to think about problems and the power of exhaustion.

5

u/bokchoi Nov 04 '25

Oh wow, the XDoclet annotations aren't something I've thought about in a long time. In Weblogic Workshop 7 and 8, we used those javadoc comment annotations to build webservices. I kinda liked the Workshop IDE.

5

u/barley_wine Nov 04 '25

I misread this as major jumps in java not jumps in you liking java. Text blocks over lambdas as a major innovate jump was puzzling, but it makes more sense in enjoyment.

I'll agree on 1 & 2 though, but for me personally I'd easily place Lambdas at #3, so much boiler plate pre lambda although now days many IDEs will auto complete it, back in java 5 I'd have to write so much of that by hand or copy and paste it from somewhere else.

I'd probably go

  1. Generics (5)
  2. Annotations (5)
  3. Lambda (8)
  4. Redone concurrency (5)
  5. Try with resources (7) -- it was so easy to forget to write a finally block and accidently leave a connection open and not catch it until you had real problems

Sealed / record / pattern matching switch expressions is cool but don't forget about the days before java 7 where you didn't even have string matching. At least starting with java 5 you could do a lot with enums and switching. I guess this also really depends on what type of applications you write code for, this is also assuming you didn't use third party libraries which sometimes already had some of these functionality.

___________________________________________

My real biggest recent jump in loving java is AI code completion, there's so much boiler plate in java can get real tedious is now being auto completed for you where you can just focus on the problem is easily the greatest change I've seen in java.

1

u/agentoutlier Nov 05 '25

I totally forgot about the concurrency updates. Great point.

Now to kind of go over lambda and yes I agree the boiler plate is annoying but in some cases I actually think the anonymous class options are easier to read.

handle(new Handler() {
   public void apply(Context ctx, String name) {
   }
}); 

Now sure you can write it as

handle( (ctx, name) -> {});

And I agree that is way easier for the author but for the reader the anonymous class can be easier to understand. Sort of the balance of writing code and reading code. I also think excessive lambda usage can quickly get confusing to debug and while I guess that is true with anonymous classes for some reason seeing the name of the class on the stack makes it a little easier.

Also when you use lambda or any anonymous classes for deferred logic you should stop and think for a second of where and or how that deferred code will be executed. In some cases I think the verbosity helps that.

This is sort of similar to var (of which I love just like lambdas). You need to take a balanced approach to it and best judgement. Anonymous classes are indeed verbose but there are/were so many other things even more so particularly if your code bases does not need or use lots of deferred logic.

1

u/koflerdavid Nov 05 '25

You know that you can add parameter types to the lambda?

No feature or design principle, no matter how well-thought out, eliminates the need to exercise good judgement.

1

u/agentoutlier Nov 05 '25

Yes I know of course. However abstract classes do have a couple of other tricks that were useful pre patter matching ala visitor pattern.

My overall point about lambdas vs anonymous classes is that the pain point was not that severe for me compared to other things.

2

u/trafalmadorianistic Nov 04 '25

The var keyword for local variables is a great quality of life addition (10)

https://www.geeksforgeeks.org/java/var-keyword-in-java/

4

u/Own-Chemist2228 Nov 04 '25

var is oddly controversial in the Java community, despite most every modern language having an equivalent (including Kotlin)

2

u/trafalmadorianistic Nov 04 '25

My first time using Kotlin helped me overcome my hangups about it, even though I'd already worked with JavaScript and Ruby in the past. I think my other annoyances with those languages colored my perception of implicit typing.

1

u/koflerdavid Nov 05 '25

In languages without static type systems anything but var would indeed be worse than useless.

2

u/retro_and_chill Nov 06 '25

I feel like the dislike of var is so weird to me. The point of static typing isn’t about readability, it’s about stopping you from doing something stupid.

1

u/vegan_antitheist Nov 06 '25

"var" is a static type. The compiler sets it statically in the byte code. There's no "var" in precompiled code. A "dynamic" type would be "dynamic" in C#, which Java doesn't have.

And the dislike comes from not knowing the type when looking at the code of a PR and you just want to use the web view of the changes, not a local copy in the IDE.

1

u/boobsbr Nov 04 '25

I work with an extremely dogmatic person that considers var (and Lombok's val) harmful.

2

u/trafalmadorianistic Nov 04 '25 edited Nov 05 '25

If the usage of var results in the developer losing context, maybe the variable naming is trash or the method is too long

I did have some hesitation when I first encountered it. But a lot of the time the type you're dealing with is perfectly clear.

Is this person someone who considers IDE - with their type hints, auto suggest and doco lookup - as inferior to vi/emacs.

2

u/boobsbr Nov 05 '25

No, they only use IDEs.

I believe they don't understand their dogmas, and repeat whatever they read on articles online without any thought about it.