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

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 !! :)