commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dipanjan Laha (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (COLLECTIONS-519) private constructors in utility classes break existing code
Date Wed, 30 Apr 2014 11:58:15 GMT

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

Dipanjan Laha commented on COLLECTIONS-519:
-------------------------------------------

It is possible to hide (not override) base class static methods. The following code snippet
{code}
public class StaticInheritence {

    public static void main(String[] args) {
        Child.someMethod();
        Base.someMethod();
    }

    public static class Base {

        public static void someMethod() {
            System.out.println("Base");
        }
    }

    public static class Child extends Base {

        public static void someMethod() {
            System.out.println("Child");
        }
    }
}
{code}
would output
{code}
Child
Base
{code}

However, I am not sure if this is a valid use case. imho having a custom util class with the
required functions and calling collection's utils methods wherever necessary is a much better
solution. Static inheritance never overrides a method but only hides it, so technically you
cannot decorate a static functions.

> private constructors in utility classes break existing code
> -----------------------------------------------------------
>
>                 Key: COLLECTIONS-519
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-519
>             Project: Commons Collections
>          Issue Type: Bug
>    Affects Versions: 4.x
>            Reporter: Radoslav Paskalev
>
> Hello,
> In collections version 4.x all utility classes (example ListUtils, MapUtils, PredicateUtils....)
have private constructors. I consider this to be a serious bug, as it breaks any possibility
the classes to be extended by the users.  The javadoc says that constructors are private in
order to prevent class instantiation but this object instantiation is not really problem and
i think it is more important to allow classes to be extended. The possibility to extend utility
classes was one of the major selling points of commons.lang and commons.collections projects.
In the latest commons.lang project the utility classes still have public constructors.
> Best Regards



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Mime
View raw message