0

I saw this sentence, but I can't understand this sentence very well. Can someone explain?

Help VM constant-fold; MAX_HIGH_SURROGATE + 1 == MIN_LOW_SURROGATE

This sentence comes from the code below:

/**
 * Determines if the given {@code char} value is a
 * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
 * Unicode high-surrogate code unit</a>
 * (also known as <i>leading-surrogate code unit</i>).
 *
 * <p>Such values do not represent characters by themselves,
 * but are used in the representation of
 * <a href="#supplementary">supplementary characters</a>
 * in the UTF-16 encoding.
 *
 * @param  ch the {@code char} value to be tested.
 * @return {@code true} if the {@code char} value is between
 *         {@link #MIN_HIGH_SURROGATE} and
 *         {@link #MAX_HIGH_SURROGATE} inclusive;
 *         {@code false} otherwise.
 * @see    Character#isLowSurrogate(char)
 * @see    Character.UnicodeBlock#of(int)
 * @since  1.5
 */
public static boolean isHighSurrogate(char ch) {
    // Help VM constant-fold; MAX_HIGH_SURROGATE + 1 == MIN_LOW_SURROGATE
    return ch >= MIN_HIGH_SURROGATE && ch < (MAX_HIGH_SURROGATE + 1);
}

I understand 'constant-fold', but How does this line of code relate to constant folding?

And , source code comes from Class 'Character'.

Constant value:

MIN_HIGH_SURROGATE = '\uD800'; MAX_HIGH_SURROGATE = '\uDBFF'

eussi
  • 31
  • 1
  • 7
  • Does this answer your question? [What is constant folding in java compiler?](https://stackoverflow.com/questions/2264178/what-is-constant-folding-in-java-compiler) – akortex Aug 09 '21 at 11:12
  • The question is clear as asked. (And I have worked out what the real answer is.) @kortex is on the right track ... but that link doesn't really explain it. – Stephen C Aug 09 '21 at 11:22
  • @akortex I understand 'constant-fold', but How does this line of code relate to constant folding? – eussi Aug 09 '21 at 12:11
  • A simple Google search can yield results as to how constant folding works. Check this link for example: https://en.wikipedia.org/wiki/Constant_folding. Also the related answer provides an explanation as to what constant folding is/does. – akortex Aug 09 '21 at 12:30

0 Answers0