RFR: JDK-6361826: (reflect) provide method for mapping strings to class object for primitive types
Joe Darcy
darcy at openjdk.org
Mon Jul 10 20:39:14 UTC 2023
On Fri, 30 Jun 2023 23:46:48 GMT, Chen Liang <liach at openjdk.org> wrote:
> The main downside of throwing an exception is that exception stack trace filling is very costly. If this API is used to process unsanitized strings like users inputs, throwing might impose performance costs for handling bad inputs.
For discussion purposes, pushed an update where the new method returns null on a non-primitive name.
To approximate normal name lookup is a Java source file (without imports), could be done with code like:
Objects.requireNonNullElse(Class.forPrimitiveName(name), name -> Class.forName(name))
-------------
PR Comment: https://git.openjdk.org/jdk/pull/14743#issuecomment-1629694729
More information about the core-libs-dev
mailing list