commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Simon Kitching (JIRA)" <j...@apache.org>
Subject [jira] Commented: (COLLECTIONS-276) *Utils classes should not be extensible or able to be instantiated.
Date Mon, 12 Nov 2007 08:08:50 GMT

    [ https://issues.apache.org/jira/browse/COLLECTIONS-276?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12541703
] 

Simon Kitching commented on COLLECTIONS-276:
--------------------------------------------

It's a proposal worth thinking about, but I'm in favour of leaving out the final and private
constructor.

One good reason to allow instances of util types is that certain tools cannot handle static
methods. For example, the JSP EL expression language always requires a bean instance; it might
be useful to configure a utils object as a "managed bean" in a JSF app for example, but this
only works if there is a constructor available. Not sure if this applies to Collection util
classes, but it certainly does to BeanUtils utility classes etc.

And this warning is only a recommended coding convention. Not everyone will want to stick
with it. If someone does want to subclass, then they can always use the @SuppressWarnings
annotation to suppress this for the appropriate methods rather than write dummy methods.

As Stephen says, I think there would need to be a specific advantage before user choice is
removed. I guess there is a performance benefit to having a final class, but I'm not sure
this is really significant.

> *Utils classes should not be extensible or able to be instantiated.
> -------------------------------------------------------------------
>
>                 Key: COLLECTIONS-276
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-276
>             Project: Commons Collections
>          Issue Type: Improvement
>    Affects Versions: Generics
>            Reporter: Stephen Kestle
>            Priority: Minor
>             Fix For: Generics
>
>
> I don't see any good reason why this CollectionUtils (and others) isn't final with a
private constructor.  There are no non-static methods, and any extension of them is going
to have to call through to the super to avoid compiler warnings.
> e.g. MyCollectionUtils.select() will provoke the warning that "static methods should
be called directly" (on CollectionUtils).
> Which would mean
> MyCollectionUtils{
> public static Collection select(){
>     return CollectionUtils.select();
> }
> Which really defeats the purpose.  In Java5, we have static imports now -  these provide
more benefit than previous extension did anyhow.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message