Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Eclipse missing wrong return type

Reply
Thread Tools

Eclipse missing wrong return type

 
 
mike
Guest
Posts: n/a
 
      08-18-2010
Hi,

We have the following method.

private int getOurId(Object value, Transaction c)
throws Exception {
if (value == null) {
return -1;
}
return ((MyInterface) value).getMyId(c);
}

And getMyId(c) returns an Integer object. We were expecting Eclipse to
give a compilation error, since return type is int for method, and
show the error in red within IDE. When running ant we get a
compilation error. We fixed with intValue().
The only difference we have is that we use 1.4 for ant and 1.5 in
Eclipse. Could that give such a difference?

//mike
 
Reply With Quote
 
 
 
 
Daniel Schwering
Guest
Posts: n/a
 
      08-18-2010
> The only difference we have is that we use 1.4 for ant and 1.5 in
> Eclipse. Could that give such a difference?


Yes, this feature is called autoboxing and new in Java 5. See
<http://download-llnw.oracle.com/javase/1.5.0/docs/guide/language/autoboxing.html>

It lets you switch between primitives and their wrapper classes.

HTH,
Daniel



 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      08-18-2010
Attribute citations.

[mike wrote:]
>> The only difference we have is that we use 1.4 for ant and 1.5 in
>> Eclipse. Could that give such a difference?


Daniel Schwering wrote:
> Yes, this feature is called autoboxing and new in Java 5. See
> <http://download-llnw.oracle.com/javase/1.5.0/docs/guide/language/autoboxing.html>
>
>
> It lets you switch between primitives and their wrapper classes.


Given that Java 5, never mind 1.4, is already officially obsolete and nearly
six years old, it behooves us to be aware by now that version 5 brought in
significant changes, and what they are.
<http://en.wikipedia.org/wiki/Java_version_history#J2SE_5.0_.28September_30.2C_2 004.29>

Any time you're dealing with different language versions, be it Java, C, BASIC
or what-have-you, it behooves you to be aware of the differences.

One of the most significant differences between Java 5 and earlier versions,
quite aside from generics and annotations and autoboxing and the rest, is the
repair to the formerly broken "memory model", that is, the rules for how data
are shared between concurrent threads.

Even though Java 6 (the current, non-obsolete version that came out
three-and-a-half years ago) introduced no significant new syntax, you still
have to remain aware of differences between it and Java 5 if you're mixing
those versions.

You can use Java 5 to build Java 1.4 projects; you just have to be sure to use
the -source, -target and -bootclasspath options correctly.

Out of curiosity, why are you stuck with such obsolete Java versions? "The
customer insists" is too shallow - what is the reasoning?

--
Lew
 
Reply With Quote
 
Mike Schilling
Guest
Posts: n/a
 
      08-19-2010


"Daniel Schwering" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>> The only difference we have is that we use 1.4 for ant and 1.5 in
>> Eclipse. Could that give such a difference?

>
> Yes, this feature is called autoboxing and new in Java 5. See
> <http://download-llnw.oracle.com/javase/1.5.0/docs/guide/language/autoboxing.html>
>
> It lets you switch between primitives and their wrapper classes.



Inn other words, the code you showed is a legal Java 1.5 program but not a
legal Java 1.4 program. Using a newer Java version for development than for
automated builds is a terrible idea, and you've just seen why.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why is return type in getfullspec().annotations named as "return"? andrew cooke Python 1 04-03-2011 01:02 AM
One type traits class (or something like that) to get the return type of a pointer to function Diego Martins C++ 5 09-05-2006 08:38 PM
Structure return type is an incomplete type. gk245 C Programming 2 05-06-2006 01:03 AM
what value does lack of return or empty "return;" return Greenhorn C Programming 15 03-06-2005 08:19 PM
Return by value -- primitive type vs class type DaKoadMunky C++ 8 05-14-2004 09:46 PM



Advertisments