jav*_*vin 0 java collections exception list
我想在java中创建一个异常列表。就像是 -
List<Exception> ex = new ArrayList<Exception>();
ex.add(NotFoundException.class);
Run Code Online (Sandbox Code Playgroud)
但这样做时我遇到了错误 -
The method add(Exception) in the type List<Exception> is not applicable for the arguments (Class<NotFoundException>)
Run Code Online (Sandbox Code Playgroud)
Eclipse IDE 建议更改为,addAll()
但这也没有解决问题。
有人可以让我知道我们如何构建 a List
or Collection
of Exception
s 吗?
您似乎对对象与其类之间的区别感到困惑。
如果你想要一个类列表:
List<Class<? extends Exception>> list = new ArrayList<Class<? extends Exception>>();
list.add(Exception.class);
Run Code Online (Sandbox Code Playgroud)
如果您想要一个例外列表:
List<Exception> list = new ArrayList<Exception>();
list.add(new Exception("Help! A problem!"));
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3259 次 |
最近记录: |