Duration.MAX_VALUE
Kevin Bourrillion
kevin.bourrillion at oracle.com
Thu Sep 4 22:22:14 UTC 2025
Of course, the problem with this code is that if `something()` is ever unexpectedly empty, suddenly that `MAX` value is going to get actually used for something, and who knows what might happen. It’s, of course, vulnerable to the “let’s just add a little” problem, same as the other case.
It would seem safer to address the empty case explicitly… but then you don’t need `MAX` anymore, you can just initialize `min` to the first value. This way you’d have a variable that was never bogus at any time.
Of course, I am not suggesting that the potential for misuse is a sufficient argument for not offering something. Only that I’m not sure this use case is motivating for offering it.
From: core-libs-dev <core-libs-dev-retn at openjdk.org> on behalf of Éamonn McManus <emcmanus at google.com>
Date: Thursday, September 4, 2025 at 3:03 PM
To: Roger Riggs <roger.riggs at oracle.com>
Cc: core-libs-dev at openjdk.org <core-libs-dev at openjdk.org>
Subject: Re: Duration.MAX_VALUE
Two typical use cases:
// 1. Sentinel
Duration min = Duration.MAX;
for (var foo : something()) {
if (foo.duration().compareTo(min) < 0) {
min = foo.duration();
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20250904/f78b4cb1/attachment.htm>
More information about the core-libs-dev
mailing list