• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compiling Problem

 
Bharadwaj Adepu
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Sheriff
Posts: 48381
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48381
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The format(Object) method of DateFormat might accept the long argument by autoboxing, which was introduced in Java 5.
 
James Basller
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48381
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic