如果罗列范例的元素主要在 Set 中使用,传统上使用 int 罗列模式,通过差别的 2 的平方数为每个常量赋值:
public class Main {
public static void main(String[] args) {
System.out.println(Utensil.NAME + Dessert.NAME);
}
}
复制代码
如果在 Sample 上运行 RunTests,输出如下:
// Two classes defined in one file. Don't ever do this!
class Utensil {
static final String NAME = "pan";
}
class Dessert {
static final String NAME = "cake";
}
复制代码
现在让我们添加一个只在抛出特定异常时才成功的测试支持。需要一个新的注解范例:
[code]// Annotation type with a parameterimport java.lang.annotation.*;/*** Indicates that the annotated method is a test method that* must throw the designated exception to succeed.*/@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.METHOD)public @interface ExceptionTest { Class