aspose file tools*
The moose likes Java in General and the fly likes I can't find out what's wrong in this code (regarding generics) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "I can Watch "I can New topic
Author

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

Bupjae Lee
Ranch Hand

Joined: May 14, 2007
Posts: 107


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

Joined: Nov 18, 2006
Posts: 689

The code example that you supplied compiled and ran on my development system.

Kaydell
Bupjae Lee
Ranch Hand

Joined: May 14, 2007
Posts: 107
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

Joined: Sep 17, 2006
Posts: 1282
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 ]

"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
I've tried in both 1.5.0_11 and 1.6.0_01 and get the same error.
Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 689


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

Joined: Feb 07, 2005
Posts: 2367
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

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.


[Jess in Action][AskingGoodQuestions]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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 ]

"I'm not back." - Bill Harding, Twister
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

Just out of curiosity, what happens if you change "extends" to "super"? Again just curious, not because I remember right now.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
super won't work in that context.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I can't find out what's wrong in this code (regarding generics)