< prev index next >

src/java.base/share/classes/java/lang/invoke/ConstantBootstraps.java

Print this page
rev 52979 : 8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: TBD


  86         return null;
  87     }
  88 
  89     /**
  90      * Returns a {@link Class} mirror for the primitive type whose type
  91      * descriptor is specified by {@code name}.
  92      *
  93      * @param lookup unused
  94      * @param name the descriptor (JVMS 4.3) of the desired primitive type
  95      * @param type the required result type (must be {@code Class.class})
  96      * @return the {@link Class} mirror
  97      * @throws IllegalArgumentException if the name is not a descriptor for a
  98      * primitive type or the type is not {@code Class.class}
  99      */
 100     public static Class<?> primitiveClass(MethodHandles.Lookup lookup, String name, Class<?> type) {
 101         requireNonNull(name);
 102         requireNonNull(type);
 103         if (type != Class.class) {
 104             throw new IllegalArgumentException();
 105         }
 106         if (name.length() == 0 || name.length() > 1) {
 107             throw new IllegalArgumentException(String.format("not primitive: %s", name));
 108         }
 109 
 110         return Wrapper.forPrimitiveType(name.charAt(0)).primitiveType();
 111     }
 112 
 113     /**
 114      * Returns an {@code enum} constant of the type specified by {@code type}
 115      * with the name specified by {@code name}.
 116      *
 117      * @param lookup the lookup context describing the class performing the
 118      * operation (normally stacked by the JVM)
 119      * @param name the name of the constant to return, which must exactly match
 120      * an enum constant in the specified type.
 121      * @param type the {@code Class} object describing the enum type for which
 122      * a constant is to be returned
 123      * @param <E> The enum type for which a constant value is to be returned
 124      * @return the enum constant of the specified enum type with the
 125      * specified name
 126      * @throws IllegalAccessError if the declaring class or the field is not




  86         return null;
  87     }
  88 
  89     /**
  90      * Returns a {@link Class} mirror for the primitive type whose type
  91      * descriptor is specified by {@code name}.
  92      *
  93      * @param lookup unused
  94      * @param name the descriptor (JVMS 4.3) of the desired primitive type
  95      * @param type the required result type (must be {@code Class.class})
  96      * @return the {@link Class} mirror
  97      * @throws IllegalArgumentException if the name is not a descriptor for a
  98      * primitive type or the type is not {@code Class.class}
  99      */
 100     public static Class<?> primitiveClass(MethodHandles.Lookup lookup, String name, Class<?> type) {
 101         requireNonNull(name);
 102         requireNonNull(type);
 103         if (type != Class.class) {
 104             throw new IllegalArgumentException();
 105         }
 106         if (name.length() != 1) {
 107             throw new IllegalArgumentException(String.format("not primitive: %s", name));
 108         }
 109 
 110         return Wrapper.forPrimitiveType(name.charAt(0)).primitiveType();
 111     }
 112 
 113     /**
 114      * Returns an {@code enum} constant of the type specified by {@code type}
 115      * with the name specified by {@code name}.
 116      *
 117      * @param lookup the lookup context describing the class performing the
 118      * operation (normally stacked by the JVM)
 119      * @param name the name of the constant to return, which must exactly match
 120      * an enum constant in the specified type.
 121      * @param type the {@code Class} object describing the enum type for which
 122      * a constant is to be returned
 123      * @param <E> The enum type for which a constant value is to be returned
 124      * @return the enum constant of the specified enum type with the
 125      * specified name
 126      * @throws IllegalAccessError if the declaring class or the field is not


< prev index next >