Clarification to TimeUnit.convert(Duration)
Pavel Rappo
pavel.rappo at gmail.com
Fri Oct 3 20:54:40 UTC 2025
TimeUnit.covert(Duration)'s receiver is an enum constant. Different
constants result in different converstions. So, it's a bit vague to
contrast "this method" to a specific conversion (in this case,
nanoseconds). Would this small clarification benefit the reader? If
so, I could create a PR.
diff --git a/src/java.base/share/classes/java/util/concurrent/TimeUnit.java
b/src/java.base/share/classes/java/util/concurrent/TimeUnit.java
index d116fb9b22b..6135461cf48 100644
--- a/src/java.base/share/classes/java/util/concurrent/TimeUnit.java
+++ b/src/java.base/share/classes/java/util/concurrent/TimeUnit.java
@@ -203,8 +203,11 @@ public long convert(long sourceDuration, TimeUnit
sourceUnit) {
* is equivalent to {@code n} (in the absence of overflow).
*
* @apiNote
- * This method differs from {@link Duration#toNanos()} in that it
- * does not throw {@link ArithmeticException} on numeric overflow.
+ * {@link #NANOSECONDS}{@code .convert(Duration)} and
+ * {@link #MILLISECONDS}{@code .convert(Duration)} differ from
+ * {@link Duration#toNanos()} and {@link Duration#toMillis()} respectively
+ * in that they do not throw {@link ArithmeticException} on numeric
+ * overflow.
*
* @param duration the time duration
* @return the converted duration in this unit,
More information about the concurrency-discuss
mailing list