Re: Java 1.6 becoming idiot-proof or just slack?
Hi Daniel,
Your existing code has the effect of parsing an int,
creating an Integer object around it, and then converting it BACK to
an int.
Oops :-)
Bit of room to move on the performance front then :-)
I've gone for the Integer.parseInt(myString) strategy and all is well, but I
couldn't let the opportunity go without whinging about the JavaScript
version of parseInt() and why my 13 byte alert message was being truncated
to 11 bytes. No one here probably cares but just in case. . .
I receive 3 ASCII numeric digits over the network which tells my client how
many more bytes to read to get the message text; in this case "013" or
thirteen bytes to come. No with Java you get a lovely 13 returned from
parseInt("013") but with Javascript you get 11 because JS has taken it upon
itself to deem the leading "0" as a radix identifier and tell me it's octal
:-( So now I have to tell it it's decimal with the second parameter.
Standards eh?
Cheers Richard Maher
"Daniel Pitts" <googlegroupie@coloraura.com> wrote in message
news:1173496633.059680.192100@c51g2000cwc.googlegroups.com...
On Mar 9, 5:41 pm, "Richard Maher" <maher...@hotspamnotmail.com>
wrote:
Hi,
I've had the following code running on Java 1.6 happily for sometime and
only after someone tried to compile it with 1.4 did I discover my
recurring
:-( school-boy error of saying intVar = new Object. I've changed the
code so
that it now it says intVar = Integer.parseInt(stringStuff) but I was
just
wondering why it ever worked. JAVAC "just knew" I wanted the .value()
instead of the object or is this really useful functionality that comes
in
Java 1B :-)
Regards Richard Maher
public class DateVMS
{
int year;
int month;
int day;
int hour;
int minute;
int second;
int hsecs;
DateVMS (String inDate)
{
this.year = new Integer(inDate.substring( 0, 4));
this.month = new Integer(inDate.substring( 4, 6));
this.month--;
this.day = new Integer(inDate.substring( 6, 8));
this.hour = new Integer(inDate.substring( 8, 10));
this.minute = new Integer(inDate.substring(10, 12));
this.second = new Integer(inDate.substring(12, 14));
this.hsecs = new Integer(inDate.substring(14, 16));
}
public int getYear()
{
return year;
}
Java 1.5 introduced something called auto boxing/unboxing, which
allows primitives to be automatically boxed by there Object
counterpoints, and visa versa.
In any case, you'd be better off using
Integer.parseInt(stringToParse). It returns an "int" rather than an
"Integer". Your existing code has the effect of parsing an int,
creating an Integer object around it, and then converting it BACK to
an int.
Oops :-)