commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 39538] - [collections] Support parametized classes with commons.collections.
Date Mon, 22 May 2006 21:49:29 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=39538>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=39538





------- Additional Comments From sergei_ivanov@vpost.ru  2006-05-22 21:49 -------
(In reply to comment #4)
> The project was done without good technical knowledge of Java 1.5 
parametized 
> classes.
> THE TYPICAL ERROR:
> class Set<E> {
>     void add(E d) {...} // that's wrong!!!
> }
> - the method add should read
>     void add(<? extends E> d) {...} // so any subclass of E is acceptable.

I am sorry to disappoint you, but the code above is not wrong. add(E) will 
accept any subclass of actual type argument. The example below is fully 
legitimate:
   Set<Number> set = new HashSet<Number>();
   set.add(new Double(0));

Please have a look, how Set<E> interface is defined in the JDK.

As for the wildcards (? extends/super E), they are mostly needed, when you 
have generic objects being passed into/returned from methods. Remember that 
you cannot pass object, which is declared as Set<Double>, to a function that 
accepts a Set<Number> as an argument, but you can do it if the argument type 
is declared as Set<? extends Number>.

Without any aim to offend you, I would strongly recommend you revisiting the 
tutorial you mentioned.

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message