On Tue, 24 May 2022 17:26:52 GMT, Roger Riggs <rri...@openjdk.org> wrote:

> Did you consider switch (class) {...} in PrimitiveTypeInfo.get?

I don't think we can switch on class instances yet. Even with preview enabled, 
best I can get is (for type incompatibility of `Class<?>` and `Class<Integer>`, 
etc.)

                return switch (cl) {
                    case Class<?> e && e == int.class -> 1;
                    case Class<?> e && e == long.class -> 2;
                    case Class<?> e && e == boolean.class -> 3;
                    case Class<?> e && e == short.class -> 4;
                    case Class<?> e && e == byte.class -> 5;
                    case Class<?> e && e == char.class -> 6;
                    case Class<?> e && e == float.class -> 7;
                    case Class<?> e && e == double.class -> 8;
                    default -> 0;
                };

to avoid type incompatibility; this is in turn implemented by a bootstrap 
method and a loop, which is of course obviously much slower.

-------------

PR: https://git.openjdk.java.net/jdk/pull/8801

Reply via email to