Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can that possible compile???

 
David Lopes
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This compiles:


This one does not compile:


I know that Integer is final and can't be extended, that is why the second example won't compile. But how is possible that the first example compiles and actually returns 35?

In Brazilian forums, there are some guys saying that could even be a Compiler Error, I doubt that but I haven't found any explanation.

Thanks for the Help.
 
Duc Vo
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would guess it works because of autoboxing feature. Autoboxing only means for the compiler to treat value type as reference type, properly in your case it will be treated as T.

Also, with the second code block if you cast the return result to T then it can be compiled.

 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am compiling from the command line and your both examples are not compiling.
Try to run them from command line.
 
Sunny Mattas
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
For me also both examples are not compiling.
And i think it has nothing to do with Integer class because following code is also not compiling.



But this is compiling with a warning

 
Duc Vo
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I compile it with eclipse 3.4. Not sure what compiler options that eclipse is using.
 
David Lopes
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Punit Singh wrote:I am compiling from the command line and your both examples are not compiling.
Try to run them from command line.


In fact, when compiling from command line (javac) the first example won't compile as well.

The strange is that my Eclipse uses the jdk 1.6 located at the same directory but of course it uses the javaw.exe to compile, not the javac.

Is there anything wrong with the javaw.exe ? oO
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Lopes wrote:
Punit Singh wrote:I am compiling from the command line and your both examples are not compiling.
Try to run them from command line.


In fact, when compiling from command line (javac) the first example won't compile as well.

The strange is that my Eclipse uses the jdk 1.6 located at the same directory but of course it uses the javaw.exe to compile, not the javac.

Is there anything wrong with the javaw.exe ? oO


This is not the first issue with eclipse, you will lots of these type of issues in future as I have got too many, so be careful, do not depend on eclipse.
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more example I remember is this one:
Here this is allowed in eclipse, but it is compile time error on command line.
 
David Lopes
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Contacted Eclipse Foundation,

They confirmed the bug and it will be corrected at the next patch.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=264843
 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought Eclipse didn't change core java and javac behavior. I thought of it as a giant GUI wrapper with added functionality. This is interesting, is Eclipse preparsing the code somehow? And for what reason?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15492
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eclipse does not use javac - it has its own built-in Java compiler, based on IBM's Jikes Java compiler. (Eclipse was originally created by IBM).

Eclipse is ofcourse supposed to work the same way as Sun's Java compiler. If it doesn't, it's a bug in Eclipse.
 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That explains things, thanks for clarifying that, Jesper.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic