this.wallet = colleague.getWallet();
Code blocks are done with 4 space indentation at the startThe correct way is IMO: colleague.getMoney() which can easily be implemented in Java, PHP etc.
I'm getting a bit tired of this constant pecking at Java (nothing personal). There are a number of questionable designs yes, there is a lot of ugly code out there, yes, but almost every alternative might have been worse:
Teaching everyone C? Good luck.
Switch to C#? Until recently that would prevent you from using Linux on your servers unless you were ready to put in technical effort and bet on MS not suing you or the upstream effort.
Perl?
PHP?
Catch my drift folks? Java filled a niche. It was almost as easy as PHP once you got started (although onboarding still is messy I think) and provided superior tooling.
Not saying Java isn't a good choice for some things. Also, if functional programming languages were more popular, they would probably be subjected to the same ridicule for the same reasons.
While I agree with you, isn't that what the new streams in Java does? The map reduce complex?
you only need two spaces, actually
https://news.ycombinator.com/formatdocThe right thing is to use an actual constructor that takes constructor parameters. Guice and Spring can both handle this correctly (you just put the @Autowired on the constructor itself). The trouble is that in Java this requires ~twice as many lines as putting a magic annotation on your fields.
[1] Make sure to not leak references to your object in your constructor. Most of the time that you would want to do this is starting a service or registering a handler, etc. The solution is to use a static creation method which first calls the constructor, and then registers/subscribes it, etc.
Also side note, how do I do the code blocks in HN comments like you did?