input.nextLine的类型安全性? [英] Type safety of input.nextLine?
问题描述
在任何情况下都可能通过将 input.nextLine()
的值分配给 String $来引发异常。 c $ c>变量与
Scanner
?
Would there ever be a case where an exception could be thrown by assigning the value of input.nextLine()
to a String
variable with the Scanner
?
就像您放
String foo = input.nextInt();
您将获得 InputMismatchException
。所以我想知道的是,是否有任何可能的方法来获取异常:
You would get an InputMismatchException
. So what I'm wondering is if there's any possible way to get an exception from:
String foo = input.nextLine();
这可能是一个愚蠢的问题,但我需要绝对确定。
It might be a dumb question but I need to be absolutely sure.
谢谢!
推荐答案
docs :
抛出:
NoSuchElementException -如果未找到任何行
IllegalStateException -如果此扫描器已关闭
Throws:
NoSuchElementException - if no line was found
IllegalStateException - if this scanner is closed
提示更轻松,更安全的生活:始终参考文档。
Tip for easier and safer life: Always refer to the docs.
这篇关于input.nextLine的类型安全性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!