Math.toIntExact why only long?
Raffaello Giulietti
raffaello.giulietti at oracle.com
Wed Nov 13 19:48:53 UTC 2024
The plan is to use the facilities described in "JEP 488: Primitive Types
in Patterns, instanceof, and switch (Second Preview)" once they become a
permanent _language_ feature.
Currently, you can perform one of the tests provided in
https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/lang/runtime/ExactConversionsSupport.html,
and then safely cast if the test succeeds.
But I suggest to rather wait for the JEP to become permanent, as it
integrates much more elegantly with the ongoing "pattern" work and the
rest of the language. You can enable preview features in JDK 23 if you'd
like to get a feeling.
HTH
Raffaello
On 2024-11-13 13:08, Andrey Turbanov wrote:
> I wounder, why java.lang.Math.toIntExact accepts only long parameter?
> I think it will quite useful to have it with float/double parameters too.
>
> Andrey Turbanov
More information about the core-libs-dev
mailing list