Handy little class, though personally I prefer the repetition of the
generic type in the constructor and regard cover methods for the
constructors to be rather silly. One trades the putative inconvenience
of repetition of type parameters for that of an additional dependency.
I guess this is mostly a matter of taste. Like you, i'll be sticking with
explicit declarations; it's usually no more than a matter of control-1 in
Eclipse anyway.
I commend you for the fullness of your doc comments, but I have a nit
about those, too. For example:
/** Creates a new LinkedList.
*
* @param collection Passed to LinkedList(Collection) constructor.
* @return A newly created LinkedList;
*/
public static <T> LinkedList<T> newLinkedList(
Collection<? extends T> collection )
{
return new LinkedList<T>( collection );
}
I was taught to include types in the @param and @return tags, thus (modulo
extra line wraps added for Usenet readability):
/** Creates a new <code>LinkedList</code>.
*
* @param collection <code>Collection < ? extends T ></code>
* passed to the <code>LinkedList(Collection)</code> constructor.
* @return LinkedList < T > A newly created LinkedList.
*/
Huh. I've never come across that idea. Given that the types are included
in the actual parameter declaration, it seems redundant to include them in
the comments too. Often, the name of the type will be useful in
constructing the description (List<Product> productsToAdd gets "@param
products the list of products to add to the cart"), but sometimes it won't
(String customerName gets "@param name the customer's name").
Since we're picking nits in Mark's sterling code, my gripe about the above
quote would be the way the parameter is described: "Passed to
LinkedList(Collection) constructor.". This is true, but not immediately
helpful - you can't determine what that actually means without referring
to the comment for that constructor. In practice, of course, everyone
knows what that means, so it does the job, but in principle, i think it'd
be better to say something like "the collection whose elements are to be
placed into this list", which is a copy-and-paste from the param comment
for the constructor.
The style of commentary employed by Mark becomes particularly enraging
when used in a big complex system with complex layered interactions, where
you end up with comments like "the value used to initialise the
ParameterBlock which is passed to the ServiceInitiator", when it could say
something like "the name of the service to start". Mark isn't committing
that sin here, of course.
By convention, the first noun in the description [of an @param] is the data
type of the parameter.
<
http://java.sun.com/j2se/javadoc/writingdoccomments/index.html#@param>
I note, however, that I learned it differently from Sun's recommendation:
The data type starts with a lowercase letter to indicate an object rather
than a class.
which would make the above @param look like this:
* @param collection the collection passed to the
* <code>LinkedList(Collection)</code> constructor.
I'm switching.
I do think that's slightly more readable.
Other weirdness in Sun's coding conventions:
http://java.sun.com/docs/codeconv/html/CodeConventions.doc7.html
Sayeth:
One blank line should always be used [...] between the local variables in
a method and its first statement
Which is kind of nutty. This sounds to me like it was written by an ex-C
programmer who still thinks the way you write methods is to declare all
the variables at the top, and then get onto the code, which i would
consider incredibly poor style.
tom