Annotation类型和Annotation本身的真正区别是什么?我的老师告诉我要解决这个问题,因为他说,这是两个不同的东西,我最好不要把它们弄混了。
有人能给我解释一下吗?我在网上找过了,但没有找到有用的东西。我真的很欣赏这一点。
谢谢。:)
@Target(value = ElementType.METHOD)
@Retention(value = RetentionPolicy.RUNTIME)
public @interface DBoperation {
public enum ParamType {
FLOAT, INT, DOUBLE, CHAR, BOOLEAN, LONG, SHORT, BYTE, REFERENCE, NONE
}
public enum OperationType {
CONNECT, DISCONNECT, UPDATE, QUERY, DELETE
}
public OperationType typOp() default OperationType.QUERY;
public ParamType typParam() default ParamType.REFERENCE;
String description();
}发布于 2014-06-18 05:17:55
您的代码示例是批注类型的声明。对于您使用注释进行注释的每个方法,都会有一个包含注释中的数据的注释。
你可以使用反射来获得注解,例如:
Class<?> annotatedClass = // put some class here
int methodIndex = // index of a annotated method
// get the annotation
// dbOperation is the annotation, DBoperation the type
DBoperation dbOperation = annotatedClass.getMethods()[methodIndex].getAnnotation(DBoperation.class);
// get data from the annotation
String operationDescription = dbOperation.description();https://stackoverflow.com/questions/24273085
复制相似问题