< prev index next >

src/java.base/share/classes/java/lang/Character.java

Print this page
rev 13019 : 8141678: sun.invoke.util.Wrapper eagerly initializes all integral type caches
Reviewed-by: TBD


 151      */
 152     public static final int MAX_RADIX = 36;
 153 
 154     /**
 155      * The constant value of this field is the smallest value of type
 156      * {@code char}, {@code '\u005Cu0000'}.
 157      *
 158      * @since   1.0.2
 159      */
 160     public static final char MIN_VALUE = '\u0000';
 161 
 162     /**
 163      * The constant value of this field is the largest value of type
 164      * {@code char}, {@code '\u005CuFFFF'}.
 165      *
 166      * @since   1.0.2
 167      */
 168     public static final char MAX_VALUE = '\uFFFF';
 169 
 170     /**





 171      * The {@code Class} instance representing the primitive type
 172      * {@code char}.
 173      *
 174      * @since   1.1
 175      */
 176     @SuppressWarnings("unchecked")
 177     public static final Class<Character> TYPE = (Class<Character>) Class.getPrimitiveClass("char");
 178 
 179     /*
 180      * Normative general types
 181      */
 182 
 183     /*
 184      * General character types
 185      */
 186 
 187     /**
 188      * General category "Cn" in the Unicode specification.
 189      * @since   1.1
 190      */


7445     /** use serialVersionUID from JDK 1.0.2 for interoperability */
7446     private static final long serialVersionUID = 3786198910865385080L;
7447 
7448     /**
7449      * Constructs a newly allocated {@code Character} object that
7450      * represents the specified {@code char} value.
7451      *
7452      * @param  value   the value to be represented by the
7453      *                  {@code Character} object.
7454      */
7455     public Character(char value) {
7456         this.value = value;
7457     }
7458 
7459     private static class CharacterCache {
7460         private CharacterCache(){}
7461 
7462         static final Character cache[] = new Character[127 + 1];
7463 
7464         static {
7465             for (int i = 0; i < cache.length; i++)

7466                 cache[i] = new Character((char)i);
7467         }
7468     }
7469 
7470     /**
7471      * Returns a {@code Character} instance representing the specified
7472      * {@code char} value.
7473      * If a new {@code Character} instance is not required, this method
7474      * should generally be used in preference to the constructor
7475      * {@link #Character(char)}, as this method is likely to yield
7476      * significantly better space and time performance by caching
7477      * frequently requested values.
7478      *
7479      * This method will always cache values in the range {@code
7480      * '\u005Cu0000'} to {@code '\u005Cu007F'}, inclusive, and may
7481      * cache other values outside of this range.
7482      *
7483      * @param  c a char value.
7484      * @return a {@code Character} instance representing {@code c}.
7485      * @since  1.5




 151      */
 152     public static final int MAX_RADIX = 36;
 153 
 154     /**
 155      * The constant value of this field is the smallest value of type
 156      * {@code char}, {@code '\u005Cu0000'}.
 157      *
 158      * @since   1.0.2
 159      */
 160     public static final char MIN_VALUE = '\u0000';
 161 
 162     /**
 163      * The constant value of this field is the largest value of type
 164      * {@code char}, {@code '\u005CuFFFF'}.
 165      *
 166      * @since   1.0.2
 167      */
 168     public static final char MAX_VALUE = '\uFFFF';
 169 
 170     /**
 171      * Zero {@code Character} constant.
 172      */
 173     private static final Character ZERO = new Character((char)0);
 174 
 175     /**
 176      * The {@code Class} instance representing the primitive type
 177      * {@code char}.
 178      *
 179      * @since   1.1
 180      */
 181     @SuppressWarnings("unchecked")
 182     public static final Class<Character> TYPE = (Class<Character>) Class.getPrimitiveClass("char");
 183 
 184     /*
 185      * Normative general types
 186      */
 187 
 188     /*
 189      * General character types
 190      */
 191 
 192     /**
 193      * General category "Cn" in the Unicode specification.
 194      * @since   1.1
 195      */


7450     /** use serialVersionUID from JDK 1.0.2 for interoperability */
7451     private static final long serialVersionUID = 3786198910865385080L;
7452 
7453     /**
7454      * Constructs a newly allocated {@code Character} object that
7455      * represents the specified {@code char} value.
7456      *
7457      * @param  value   the value to be represented by the
7458      *                  {@code Character} object.
7459      */
7460     public Character(char value) {
7461         this.value = value;
7462     }
7463 
7464     private static class CharacterCache {
7465         private CharacterCache(){}
7466 
7467         static final Character cache[] = new Character[127 + 1];
7468 
7469         static {
7470             cache[0] = ZERO;
7471             for (int i = 1; i < cache.length; i++)
7472                 cache[i] = new Character((char)i);
7473         }
7474     }
7475 
7476     /**
7477      * Returns a {@code Character} instance representing the specified
7478      * {@code char} value.
7479      * If a new {@code Character} instance is not required, this method
7480      * should generally be used in preference to the constructor
7481      * {@link #Character(char)}, as this method is likely to yield
7482      * significantly better space and time performance by caching
7483      * frequently requested values.
7484      *
7485      * This method will always cache values in the range {@code
7486      * '\u005Cu0000'} to {@code '\u005Cu007F'}, inclusive, and may
7487      * cache other values outside of this range.
7488      *
7489      * @param  c a char value.
7490      * @return a {@code Character} instance representing {@code c}.
7491      * @since  1.5


< prev index next >