Java - Annotation Member Class Type


The following code shows how to use Class as annotation element value.



@interface TestCase {
  Class<? extends Throwable> willThrow() default Exception.class;

public class Main {
  // Must throw IOExceptionn
  @TestCase(willThrow = IOException.class)
  public static void testCase1() {
    // Code goes here
  }/*from w  w  w  .j a v a 2s .  c  o  m*/

  // We are not expecting any exception
  public static void testCase2() {
    // Code goes here