Not quite. Java has had introspection since 1996. What JavaBeans brought is a consistent way of naming your methods so that classes can be introspected and made sense of in a way that allows composition and interaction.
Also side note, how do I do the code blocks in HN comments like you did?
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.
I have wondered what that was about. Thanks for clearing it up.
It is strange how the lack of a feature people really need (or want) can cause them to do weird things to work around that lack.
Consider:
You are born with no body parts.
Should anyone attempt to interact with you before your organs have finished arriving you will die. Throws a NullPointerException because the class designer improperly initialized the instance. The designer should have provided a constructor. One by one, your organs are pushed into you.Instead, the class designer probably followed the JavaBean pattern and provided a setter method for Organs:
etc.(For those that don't remember: The JavaBean idea arose because early versions of Java had no way of performing introspection, something that software tools really, really need. JavaBeans broke object encapsulation by design. Many programmers had to write beans to take advantage of their tools, and learned a very bad habit.)