你可以。这是Jackson库(而忽略了评论)一个例子:
package com.fasterxml.jackson.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.FIELD,
ElementType.METHOD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@JacksonAnnotation
public @interface JsonSubTypes {
public Type[] value();
public @interface Type {
/**
* Class of the subtype
*/
public Class<?> value();
/**
* Logical type name used as the type identifier for the class
*/
public String name() default "";
}
}
而且这里有一个例子用法:
@JsonSubTypes({
@JsonSubTypes.Type(value = TestSystemEvent.class, name = "TestEvent"),
})
public interface SystemEvent {
}
您是否打算创建一个框架来使用它? –
MyAnnotation是否来自SomeType? (对,我不这么认为)。那么你想如何创建一个'SomeType'数组,其中包含一个不是'SomeType'类型的元素? –
@TimBiegeleisen是的。 – Sayid