Что заканчивается, когда Вы передаете пустую строку перечислению Java .valueOf вызов?

Вам не нужно использовать цикл for с оператором setInterval. Попробуйте это:

var list = Array(...);
var x = 0;

setInterval(function() {

    if (x < list.length;) {
        list[x] += 10;
        console.log(x+"=>"+list[x]);
    }

    else return;

    x++;
}, 5000);
29
задан Jay R. 24 May 2009 в 20:04
поделиться

4 ответа

Вы должны получить исключение IllegalArgumentException , если имя не является именем перечисления (которое не будет для пустой строки). Это генерируется в документации API для всех методов enum valueOf . Вы должны получить NullPointerException для null . Вероятно, не рекомендуется давать фиктивное значение переменной String (и не допускать, чтобы последний случай / по умолчанию не выполнялся).

50
ответ дан 28 November 2019 в 01:19
поделиться

Я только что попробовал ваш код. Это вызывает исключение IllegalArgumentException . Как и указано в документации.

7
ответ дан 28 November 2019 в 01:19
поделиться

метод: valueOf

Returns the enum constant of the specified enum type with the specified name. The name must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters:
    enumType - the Class object of the enum type from which to return a constant
    name - the name of the constant to return 
Returns:
    the enum constant of the specified enum type with the specified name 
Throws:
    IllegalArgumentException - if the specified enum type has no constant with the specified name, or **the specified class object does not represent an enum type** 
    NullPointerException - if **enumType or name is null**

, чтобы отмечать эти исключения,

3
ответ дан 28 November 2019 в 01:19
поделиться

Status.valueOf ведет себя так же, как Enum.valueOf

2
ответ дан 28 November 2019 в 01:19
поделиться
Другие вопросы по тегам:

Похожие вопросы: