Programming puzzle: dates
Does your API have date utility methods? If so, the answer to the following quiz may surprise you a little. Suppose we have a method that subtracts two dates and returns the result in milliseconds.
import java.util.Date;public long subtract(Date d1, Date d2) {
if(d1 == null || d2 == null) {
throw new IllegalArgumentException();
}
return d1.getTime() - d2.getTime();
}The question is where the problem lies and how to fix it.
Related articles
Related CZ Podcast episodes
- #3 · Java 6 SE, Vývoj webových aplikací
Dagi and Filemon discuss Java 6 and web application frameworks. · Czech audio
- #1 · Vývojová prostředí v Javě
The first CZ Podcast episode looks at Java development environments. · Czech audio