-
Notifications
You must be signed in to change notification settings - Fork 9.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix public APIs for kotlin.time.Duration #8355
Conversation
Use this as our preferred API for accepting a duration in OkHttpClient and CacheControl. Also hide these functions from the Java API.
maxAge: Int, | ||
timeUnit: DurationUnit, | ||
) = commonMaxAge(maxAge, timeUnit) | ||
@JvmSynthetic // Don't expose @JvmInline types in the Java API. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't need any of these annotations as functions accepting value types should already have their names mangled to include a hypen which is an invalid character in Java method names. The API dump should confirm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
) = commonMaxAge(maxAge, timeUnit) | ||
@JvmSynthetic // Don't expose @JvmInline types in the Java API. | ||
fun maxAge(maxAge: Duration) = apply { | ||
require(maxAge.inWholeSeconds >= 0) { "maxAge < 0: ${maxAge.inWholeSeconds}" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do
require(maxAge.inWholeSeconds >= 0) { "maxAge < 0: ${maxAge.inWholeSeconds}" } | |
require(!maxAge.isNegative()) { "maxAge < 0: ${maxAge.inWholeSeconds}" } |
you avoid having to do an internal conversion solely to perform the check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed to call inWholeSeconds once.
* precision; finer precision will be lost. | ||
*/ | ||
@ExperimentalOkHttpApi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer experimental!
maxAge: Int, | ||
timeUnit: DurationUnit, | ||
) = commonMaxAge(maxAge, timeUnit) | ||
@JvmSynthetic // Don't expose @JvmInline types in the Java API. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
) = commonMaxAge(maxAge, timeUnit) | ||
@JvmSynthetic // Don't expose @JvmInline types in the Java API. | ||
fun maxAge(maxAge: Duration) = apply { | ||
require(maxAge.inWholeSeconds >= 0) { "maxAge < 0: ${maxAge.inWholeSeconds}" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed to call inWholeSeconds once.
Use this as our preferred API for accepting a duration in OkHttpClient and CacheControl.
Also hide these functions from the Java API.