My first feeling about avoding annotations is mixed though. Especially the default constructor inspection feels strange:
"By default the constructor with no parameters is selected (if available) or the 1st (in sequence of definition within the class) with any parameters."
The ordering of constructors is a very subtle way to guide injection, i really like annotations for that. They are a bit more explicit. They serve as documentation and don't
come with a runtime performance penalty.
Just my personal feeling, and as I understood your documentation, adding annotations should be an easy addition if I desire to do so, right?
From google-guice newsgroup:My first feeling about avoding annotations is mixed though. Especially the default constructor inspection feels strange:
"By default the constructor with no parameters is selected (if available) or the 1st (in sequence of definition within the class) with any parameters."Actually I started with that in the very beginning and never had to change since I use just one constructor having the parameters that are needed.Definitely nothing that is very decided.
The ordering of constructors is a very subtle way to guide injection, i really like annotations for that. They are a bit more explicit. They serve as documentation and don't
come with a runtime performance penalty.Annotations come with same performance penalty as inspecting existing constructors. Both is a lookup via reflection.
Just my personal feeling, and as I understood your documentation, adding annotations should be an easy addition if I desire to do so, right?Exactly. http://www.silkdi.com/userguide/intro.html#customise You can use *your* annotation very easy if this is what you like.
Jan
"By default the constructor with no parameters is selected (if available) or the 1st (in sequence of definition within the class) with any parameters."
/**
* Returns an array of <code>Constructor</code> objects reflecting all the
* constructors declared by the class represented by this
* <code>Class</code> object. These are public, protected, default
* (package) access, and private constructors. The elements in the array
* returned are not sorted and are not in any particular order. If the
* class has a default constructor, it is included in the returned array.
* This method returns an array of length 0 if this <code>Class</code>
* object represents an interface, a primitive type, an array class, or
* void.
*
* <p> See <em>The Java Language Specification</em>, section 8.2.
*
* @return the array of <code>Constructor</code> objects representing all the
* declared constructors of this class
* @exception SecurityException
* If a security manager, <i>s</i>, is present and any of the
* following conditions is met:
*
* <ul>
*
* <li> invocation of
* <tt>{@link SecurityManager#checkMemberAccess
* s.checkMemberAccess(this, Member.DECLARED)}</tt> denies
* access to the declared constructors within this class
*
* <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of <tt>{@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()}</tt> denies access to the package
* of this class
*
* </ul>
*
* @since JDK1.1
*/
public Constructor<?>[] getDeclaredConstructors() throws SecurityException {
// be very careful not to change the stack depth of this
// checkMemberAccess call for security reasons
// see java.lang.SecurityManager.checkMemberAccess
checkMemberAccess(Member.DECLARED, ClassLoader.getCallerClassLoader());
return copyConstructors(privateGetDeclaredConstructors(false));
}
Is the order of the constructors returned by a call to Class.getConstrucots somehow defined?
The elements in the array returned are not sorted and are not in any particular order.
which makes me think that there is no particular order defined in the bytecode and therefore I feel it problematic to choose the "first" constructor.
I will change docs and impl. to have a more determined behavior. But it is still just 1 line of code away to pick the constructor however you wan't it.