wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Compiling Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Compiling Problem" Watch "Compiling Problem" New topic
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: 37950
    
  22
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: 37950
    
  22
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: 37950
    
  22
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compiling Problem
 
Similar Threads
date format
Eclips error
calling javabean from jsp
How to print default date in required format
date format