本文整理匯總了Java中java.lang.annotation.RetentionPolicy.values方法的典型用法代碼示例。如果您正苦於以下問題:Java RetentionPolicy.values方法的具體用法?Java RetentionPolicy.values怎麽用?Java RetentionPolicy.values使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.annotation.RetentionPolicy
的用法示例。
在下文中一共展示了RetentionPolicy.values方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test
import java.lang.annotation.RetentionPolicy; //導入方法依賴的package包/類
public void test() throws TestFailedException {
try {
String template = getSource(getSourceFile(templateFileName));
for (int i = 0; i < 2; ++i) {
for (String repeatable : new String[] {"", "@Repeatable(Container.class)"}) {
for (RetentionPolicy policy : RetentionPolicy.values()) {
final int finalI = i;
Map<String, String> replacements = new HashMap<String, String>(){{
put("%POLICY%", policy.toString());
if (finalI != 0) {
put("default.*\n", ";\n");
}
put("%REPEATABLE%", repeatable);
}};
test(template, replacements, i == 0);
}
}
}
} catch (Throwable e) {
addFailure(e);
} finally {
checkStatus();
}
}
示例2: annotationTest
import java.lang.annotation.RetentionPolicy; //導入方法依賴的package包/類
@Test(enabled = false) // TODO 8080354
public void annotationTest() {
assertEval("import java.lang.annotation.*;");
for (RetentionPolicy policy : RetentionPolicy.values()) {
String annotationSource =
"@Retention(RetentionPolicy." + policy.toString() + ")\n" +
"@interface A {}";
assertEval(annotationSource);
String classSource =
"@A class C {\n" +
" @A C() {}\n" +
" @A void f() {}\n" +
" @A int f;\n" +
" @A class Inner {}\n" +
"}";
assertEval(classSource);
String isRuntimeVisible = policy == RetentionPolicy.RUNTIME ? "true" : "false";
assertEval("C.class.getAnnotationsByType(A.class).length > 0;", isRuntimeVisible);
assertEval("C.class.getDeclaredConstructor().getAnnotationsByType(A.class).length > 0;", isRuntimeVisible);
assertEval("C.class.getDeclaredMethod(\"f\").getAnnotationsByType(A.class).length > 0;", isRuntimeVisible);
assertEval("C.class.getDeclaredField(\"f\").getAnnotationsByType(A.class).length > 0;", isRuntimeVisible);
assertEval("C.Inner.class.getAnnotationsByType(A.class).length > 0;", isRuntimeVisible);
}
}
示例3: retentionPolicyTestCaseGenerator
import java.lang.annotation.RetentionPolicy; //導入方法依賴的package包/類
@DataProvider(name = "retentionPolicyTestCase")
public Object[][] retentionPolicyTestCaseGenerator() {
List<Object[]> list = new ArrayList<>();
for (RetentionPolicy policy : RetentionPolicy.values()) {
list.add(new Object[]{policy});
}
return list.toArray(new Object[list.size()][]);
}
示例4: test_values
import java.lang.annotation.RetentionPolicy; //導入方法依賴的package包/類
/**
* @throws Exception
* @tests java.lang.annotation.RetentionPolicy#values()
*/
@SuppressWarnings("nls")
public void test_values() throws Exception {
RetentionPolicy[] values = RetentionPolicy.values();
assertTrue(values.length > 1);
Arrays.sort(values);
assertTrue(Arrays.binarySearch(values, RetentionPolicy.RUNTIME) >= 0);
}