Catch a generic exception in Java?

前端 未结 7 1163
不知归路
不知归路 2020-12-11 14:26

We use JUnit 3 at work and there is no ExpectedException annotation. I wanted to add a utility to our code to wrap this:

 try {
     someCode();         


        
7条回答
  •  萌比男神i
    2020-12-11 15:00

    Catch clause with type parameter is not possible:
    http://docs.oracle.com/javase/tutorial/java/generics/restrictions.html#cannotCatch

提交回复
热议问题