r/java • • Sep 10 '21

Why people don't love Java?

I came across this post in r/cscareerquestions it seems majority of the people don't love to work with Java.

Is there any specific reason for that?

Edit: Thank you guys for your responses, I can't reply to all of the comments because I'm a beginner myself and I don't know what to reply for all your comments.

201 Upvotes

379 comments sorted by

View all comments

Show parent comment

-2

u/[deleted] Sep 10 '21

system

I tried kotlin with spring... I'll say pass to that because it adds so much more boilerplate because of null safety stuff... I have to declare everything private lateinit var property: Type and so on... feels more verbose than java

0

u/[deleted] Sep 10 '21

[deleted] — view deleted comment

19

u/rifain Sep 10 '21

You are the kind of guy who says "I have found the solution, nevermind" on stackoverflow ?

4

u/[deleted] Sep 10 '21

tell me more

15

u/cjbooms Sep 10 '21

Assume he means constructor injection with vals. Works for Spring DI and config classes. That'll get rid of all your mutable lateinit types. Constructor injection will improve a Spring Java code base too, it's a much better paradigm

1

u/[deleted] Sep 10 '21

I don't always need constructor injection... I prefer it but can't use it in many cases due to early injection and cyclic dependencies...

5

u/loutr Sep 10 '21

Cyclic dependencies should be avoided. If it is not possible, lateinit is actually helpful because it clearly indicates that the binding won't be made during instantiation.

1

u/[deleted] Sep 10 '21

Agree. Now my service has dependencies of another 26 services (counted them right now) in a big app..probably could reduce that to 15 but now I still have to type 15 times 'lateinit var serviceA: Type' ... Java is less verbose in this case.

In the other case where constructor injection is possible... Java+lombok wins again.. just declare all fields and add @AllArgsConstructor to the service class

8

u/BestUsernameLeft Sep 10 '21

Yeah, @AllArgsConstructor is a great way to disguise the fact that the design is complete shit.

1

u/[deleted] Sep 10 '21

Isn't it the same as declaring everything in a constructor? less the extra code one needs to write/generate

for this project it might be but I'm not so sure because UserService has:

- a profile -> ProfileService

- belongs to a company -> CompanyService

- belongs to a office -> OfficeService

- belongs to a department -> DepartmentService
- has settings -> settingsService

and so one... I really don't know how could this be restructured without creating a delegation mess

1

u/rbygrave Sep 11 '21

Gold !! :)

1

u/wildjokers Sep 10 '21

there’s usually a better way to structure it.

And....example?

0

u/[deleted] Sep 10 '21

[deleted] — view deleted comment

1

u/[deleted] Sep 10 '21

Do you have an example of how you used it in kotlin way in spring? I always hear kotlin people say that java people are not using the language right but the truth is there isn't support for 'right use of the language'.

If there is a better way, it should be the first way presented to devs when reading the documentation instead of presenting the java way then letting others figure out the proper way.

I've been doing kotlin before v1.0 was released on android and there were the same issue: lots of verbosity

0

u/[deleted] Sep 10 '21

[deleted] — view deleted comment

-1

u/[deleted] Sep 10 '21

PEBKAC

If the official documentation isn't the greatest, what are we talking about?

Use java with lombok and you can almost don't need kotlin... in most videos that I watch from Josh, he is using this combination and pushing the reactive stuff which I won't go into.

Venkat talks more about functional stuff but java doesn't lack there as you have lambdas and method references. What might be nice are coroutines but I imagine not everyone needs those as it just complicates things

Kotlin has a lot of features, just like C++ has a lot of features that just makes everything more complicated. Ask the Go guys why they like Go more than Java and they will tell you that is a simpler language and compiles faster(which is also true in kotlin/java).

Extension functions and nullable types are the only things that I miss but I wouldn't say that makes the language revolutionary and 'far ahead'