participate


Generics - Contravariance Problem when using Generics...
<<   Back to Forum  |   Give us Feedback
This topic has 4 replies on 1 page.
austall
Posts:3
Registered: 2/3/98
Contravariance Problem when using Generics...   
Jul 12, 2003 9:44 AM

 
Hi
I'm new to this forum. HOpe this question wasn't ask before. When searching the forums I didn't find an asnswer for my problem... My question is, what's wrong with this code:

Vector<-Integer> v = new Vector<Number>();
Integer in = new Integer(5);
v.add(in);

My compiler says
javac15 -warnunchecked CotV1.java

CotV1.java:10: reference to add is ambiguous, both method add(E) in java.util.AbstractCollection<=-java.lang.Integer> and method add(E) in java.util.AbstractList<=-java.lang.Integer> match
v.add(in);
^
1 error

My java environemnt is Windows 2000 SP4 German
java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)

with the adding_generics-2_0-ea package

MfG
 
brucechapman
Posts:683
Registered: 11/24/98
Re: Contravariance Problem when using Generics...   
Jul 13, 2003 6:39 PM (reply 1 of 4)  (In reply to original post )

 
Your code looks fine. I think its a compiler bug.

if Neal or Christian don't respond here within a day or two, please report this to mailto:jsr14-prototype-comments@sun.com


Its the old invalid assumption bug, where the invalid assumption is that your code is wrong when in fact its a system bug - the trouble with these is that they chew up heaps of effort before you convince yourself that you are doing everything right, and therefore the compiler or whatever is faulty. Note, with these beta's you should drop the assumption that the compiler is always right. Its only nearly always right. :)

Bruce
 
austall
Posts:3
Registered: 2/3/98
Re: Contravariance Problem when using Generics...   
Jul 14, 2003 12:00 AM (reply 2 of 4)  (In reply to #1 )

 
Thanks! Anyway, it's quite interesting to play around with the possibilities the generics offer...
 
fredastaire
Posts:97
Registered: 1/3/00
Re: Contravariance Problem when using Generics...   
Jul 14, 2003 1:04 PM (reply 3 of 4)  (In reply to original post )

 
This is a known bug. It's listed at
http://cag.lcs.mit.edu/~cananian/Projects/GJ/
as Sun bug 4872698
http://developer.java.sun.com/developer/bugParade/bugs/4872698.html
which I believe was first reported here:
http://forum.java.sun.com/thread.jsp?forum=316&thread=406516
 
cplesner
Posts:17
Registered: 6/1/03
Re: Contravariance Problem when using Generics...   
Jul 16, 2003 8:03 AM (reply 4 of 4)  (In reply to #1 )

 
Whew, I just made it before the two-day deadline!

Yes it's a well-known bug. I'm sorry about the headaches this bug has caused and keeps causing -- it won't be there in the next prototype.


-- Christian
 
This topic has 4 replies on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 29
  • Guests : 132

About Sun forums
  • Sun Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Sun Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums