| Author |
Compiling Problem
|
Bharadwaj Adepu
Ranch Hand
Joined: Dec 30, 2007
Posts: 99
|
|
This is a piece of a code am trying to compile This is compeling fine when i compile with javac -source 1.5 -target 1.5 But this gives the following error when i compile with javac -source 1.4 -target 1.4 What might be the problem. Ive gone through APIs of both 1.5 and 1.4 version of Java, but not able to find out
|
SCJP 1.5
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
|
The API documentation and the error message tell it all; you are passing the wrong sort of argument to the format() method. It takes Date, and you are passing getTime(). You want to pass the Date with the getTime() method call removed.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
|
The format(Object) method of DateFormat might accept the long argument by autoboxing, which was introduced in Java 5.
|
 |
James Basller
Ranch Hand
Joined: Sep 07, 2008
Posts: 58
|
|
Originally posted by Bharadwaj Adepu: This is a piece of a code am trying to compile This is compeling fine when i compile with javac -source 1.5 -target 1.5 But this gives the following error when i compile with javac -source 1.4 -target 1.4 What might be the problem. Ive gone through APIs of both 1.5 and 1.4 version of Java, but not able to find out
Yes, Campbell is right!!! Here you are passing long where dateFormat.format() parameter accepts Date Object.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
No, I think you have misunderstood my reply. The long is autoboxed to a Long, and passed as an argument to the overloaded method with Object as its parameter type. Not to the overloaded version taking Date as its parameter type. Since autoboxing was introduced in Java5, that explains why it won't work in Java4 . . . At least I think that's right. CR
|
 |
 |
|
|
subject: Compiling Problem
|
|
|