Console cons = System.console();
Вышеупомянутая строка кода создает минусы в качестве нулевой ссылки. Код и вывод приведены ниже:
Console cons = System.console();
if (cons != null) {
System.out.println("Enter single character: ");
char c = (char) cons.reader().read();
System.out.println(c);
}else{
System.out.println(cons);
}
Выход:
null
blockquote>Код был протестирован на macbook pro с java-версия "1.6.0_37"