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 <[email protected]> on behalf of Éamonn 
McManus <[email protected]>
Date: Thursday, September 4, 2025 at 3:03 PM
To: Roger Riggs <[email protected]>
Cc: [email protected] <[email protected]>
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();
  }
}

Reply via email to