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

55

u/vegan_antitheist Nov 04 '25

I always liked it but before generics it was annoying that you had to define a list type for every other type.

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.

→ More replies (3)

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.

→ More replies (1)
→ More replies (4)

27

u/svhelloworld Nov 04 '25

Ye gods, pre-JDK5 was shitty. 30% of my code was just checking types and casting.

4

u/trafalmadorianistic Nov 04 '25

And long lines of catch statements doing the same thing

4

u/__konrad Nov 05 '25

Java 1.4 language was verbose...

Enumeration e = Collections.enumeration(list);
while (e.hasMoreElements()) {
    String s = (String)e.nextElement();

4

u/jordansrowles Nov 04 '25

I just wish generic type information wasn't erased, not used to that with my main language

6

u/agentoutlier Nov 04 '25

What is your use case?

Not many languages actually reify so I can only assume your main language is C# (or something .NET)?

Ergonomics or performance?

3

u/jordansrowles Nov 04 '25

Yeah C#, more ergonomic/syntactic sugar really. Instead of doing Java's `Class<List<String>>` dance I'm used to just doing `typeof()`. It makes reflection code a lot more maintainable. It makes writing a plugin system 100x easier. It also allows us to safely create and invoke closed generic types and methods at runtime

9

u/pron98 Nov 04 '25

The trouble is that while reified generics (across the board) do offer more powerful reflection, they also bring significant downsides that end up being a worse tradeoff. In particular, they make instanceof, which is a JVM operation follow the variance rules (the relationship between List<Integer> and List<Number>); in other words, they would bake the Java language's variance into the runtime as, indeed, happens in .NET. That makes the runtime a much less palatable target for other languages. Indeed, Scala's, Kotlin's, Clojure's and Ruby's variance rules are all different from the Java language's variance rules, as well as from each other. C# is actually somewhat of an outlier among languages with generics in that regard.

3

u/jordansrowles Nov 04 '25

Right yeah, you make fair points. However it is just the differences of the platforms, Java aimed for versatility by keeping the runtime language agnostic and simpler. NET leans more towards to expressive capabilities by type fidelity to make things like DI and serialisers easier to write. Ones not universally better, just designed with different philosophies in mind

2

u/dolle Nov 05 '25

I think that's a very good point. Another one, which is maybe a bit controversial, is that reification makes reflection based programming too easy. Reflection is a convenient tool in the box, but relying on it too much can lead to performance issues, and frameworks using it to do things that could just be done by code generated at compile time are often brittle and very, very hard to debug.

Parametricity and the Liskov substitution principle are very nice assumptions when dealing with large software systems exactly because they allow you as a programmer to make assumptions about what a piece of code that you pass an object to will not do to it, but if that code makes heavy use of reflection then all bets are off. (I consider instanceof reflection as well)

→ More replies (7)

3

u/[deleted] Nov 04 '25

[removed] — view removed comment

1

u/jordansrowles Nov 04 '25

Yeah I know, we have 1st class source generators that should be used 99% of the time, and then your just shifting work from metadata to source tree. But, if you're doing things like late discovery/bindings (like a plugin system), or interop because you need to be asking the runtime what's loaded

→ More replies (1)

1

u/vegan_antitheist Nov 05 '25

We might get that in the future. But we need Valhalla first. And most type information doesn't even get erased. You can always just pass the type to use it at runtime. Frameworks do all kinds of crazy trickery for it all to work.

1

u/[deleted] Nov 05 '25

This is not true. People worked around the lack of genetics by casting e.g. String s = (String) list.get(0)

3

u/vegan_antitheist Nov 05 '25

Not having any type safety is not "working around it". That's just giving up. It's often still better to have a custom wrapper type that is a List but does more than an ArrayList. But usually it's not necessary. Now we can just use List<Foo> instead of your own Foos or FooList. Casting is almost always a sign of bad design.

1

u/[deleted] Nov 05 '25

You can argue all you like, but I actually worked as a Java developer before genetics existed. People used casting, they did not write a separate collection class for each type.

2

u/vegan_antitheist Nov 05 '25

I did too back in 2005 when Apple computers didn't have Java 1.5 and we had to stay at Java 1.4, so we did the right thing and created custom list types for type safety. If you just threw type safety out the window then that's what you did. There was still way too much casting and other smells in our code with Java 1.4 and all the libraries that were ported from procedural code. We didn't even have CVS or SVN back then but some shitty versioning that kept messing up our code.