Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I can't find out what's wrong in this code (regarding generics)

 
Bupjae Lee
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Compiler fails to accept this code with this error message:



I think this error message means <U extends Number> fails to accept <Integer>, but I don't know why.
[ June 10, 2007: Message edited by: Bupjae Lee ]
 
Kaydell Leavitt
Ranch Hand
Posts: 689
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code example that you supplied compiled and ran on my development system.

Kaydell
 
Bupjae Lee
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Kaydell Leavitt

Can I ask your development system?

I made that code in Notepad, and I compiled with JDK javac 1.6.0_01 in Command Prompt
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bupjae Lee:
Can I ask your development system?




javac 1.5.0_12

[ hard to get the ^ character positoned correctly ]

[ June 11, 2007: Message edited by: Nicholas Jordan ]
[ June 11, 2007: Message edited by: Nicholas Jordan ]
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've tried in both 1.5.0_11 and 1.6.0_01 and get the same error.
 
Kaydell Leavitt
Ranch Hand
Posts: 689
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dear Kaydell Leavitt:
Can I ask your development system?


It compiled under my development system, Eclipse 3.2.2 for Mac OS X, running java 1.5.0_07. Then, when I went back for a second-look, I could have sworn that I was getting an exception. And when I went back to see what kind of exception, the code started working.

I'm consistently getting an output of "10" now.



Kaydell

[Edited to delete inconsistencies]
[ June 11, 2007: Message edited by: Kaydell Leavitt ]
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried it with Eclipse under Windows, and it also compiled and ran. I think the issue is that Eclipse doesn't use the pure Java compiler from Sun.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This looks like a tricky language corner issue, as Sun's compiler and the Eclipse compiler disagree on what's correct. I'm going to move this to our Java in General (Intermediate) forum and call in the big guns.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hm, now I can't really comment without looking egotistical. But EFH asked me to comment, so here I am. I'm pleased he has such a high opinion of me, but I'm pretty sure there are several other regular posters who are at least as qualified. Including (or especially) Dr. Friedman-Hill himself. Anyway...

Thus far, I don't see any reason for the error thrown by Sun's compiler. I would say it looks like a bug. I don't see any good justification for it - it looks like Sun screwed up, period. I will continue to look into it, but so far, I'm not seeing any justification for the behavior of Sun's compiler here.

If anyone else reading this has any further insight, please share it.
[ June 12, 2007: Message edited by: Jim Yingst ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just out of curiosity, what happens if you change "extends" to "super"? Again just curious, not because I remember right now.

Mark
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
super won't work in that context.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic