In using eclipse indigo, with the compiler set to 1.6, I was crashing at runtime on the following:
I got an IllegalArgumentException, "Cannot format given Object as a Date".
I scratched my head for a while, then finally realized that I was passing a Calendar object to SimpleDateFormat.format(), which takes a Date object.
The odd thing is that it wasn't caught at compile time. Calendar doesn't extend Date. The documentation I find online for SimpleDateFormat and DateFormat in version 1.4 and version 6 say that the format method takes a Date object. The source code for version 6 has 'public final
String format(Date date)', and then it calls the method that likely throws this error. When I changed the call to be
, things worked as expected.
Why didn't the compiler catch this?
rc