The spec says:
"A top-level Java class is a managed bean if it is defined to be a
managed bean by any other Java EE specification, or if it meets all of
the following conditions:
• It is not a non-static inner class.
• It is a concrete class, or is annotated @Decorator.
...
• It has an appropriate constructor—either:
• the class has a constructor with no parameters, or
• the class declares a constructor annotated @Inject.
All Java classes that meet these conditions are managed beans and thus
no special declaration is required to define a man- aged bean."
Which part of the word "all" do you not understand? ;-)
But more importantly, there is a very good usecase for allowing this
case. I might be using an interface at the injection point, and hiding
the actual implementation of the client by declaring the bean class
package private. This is just like having a factory method defined
within the package, so I'm not "breaking" any normal Java behavior
here.
Now, look, I'm slightly sympathetic to the idea that we could have
chosen to say that bean constructors must not be private private, and
that if the constructor with no parameters is private, then the class
is not a bean. That would not be a completely unreasonable behavior
(it doesn't necessarily follow from first principles, but you could do
a bit of guessing about user intent and say that it's reasonable). But
we didn't say that. We said something else. And the spec is now final.
So for portability, we all have to comply with that.
--
Gavin King
gavin.king(a)gmail.com
http://in.relation.to/Bloggers/Gavin
http://hibernate.org
http://seamframework.org