java.lang.annotation.Retention类的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(5.7k)|赞(0)|评价(0)|浏览(132)

本文整理了Java中java.lang.annotation.Retention类的一些代码示例,展示了Retention类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Retention类的具体详情如下:
包路径:java.lang.annotation.Retention
类名称:Retention

Retention介绍

暂无

代码示例

代码示例来源:origin: Blankj/AndroidUtilCode

public final class BusUtils {

  @Target({ElementType.METHOD})
  @Retention(RetentionPolicy.CLASS)
  public @interface Subscribe {
    String name() default "";
  }
}

代码示例来源:origin: google/error-prone

private static RetentionPolicy effectiveRetentionPolicy(Element element) {
 RetentionPolicy retentionPolicy = RetentionPolicy.CLASS;
 Retention retentionAnnotation = element.getAnnotation(Retention.class);
 if (retentionAnnotation != null) {
  retentionPolicy = retentionAnnotation.value();
 }
 return retentionPolicy;
}

代码示例来源:origin: square/retrofit

public final class JsonQueryParameters {
 @Retention(RUNTIME)
 @interface Json {

代码示例来源:origin: com.google.inject/guice

/** Returns true if the given annotation is retained at runtime. */
public static boolean isRetainedAtRuntime(Class<? extends Annotation> annotationType) {
 Retention retention = annotationType.getAnnotation(Retention.class);
 return retention != null && retention.value() == RetentionPolicy.RUNTIME;
}

代码示例来源:origin: Netflix/Priam

public static class PriamAnnotation {
  @Retention(RetentionPolicy.RUNTIME)
  //    @Target({ElementType.FIELD,ElementType.METHOD})
  public @interface GsonIgnore {
    // Field tag only annotation
  }
}

代码示例来源:origin: looly/hutool

/**
 * 获取注解类的保留时间,可选值 SOURCE(源码时),CLASS(编译时),RUNTIME(运行时),默认为 CLASS
 * 
 * @param annotationType 注解类
 * @return 保留时间枚举
 */
public static RetentionPolicy getRetentionPolicy(Class<? extends Annotation> annotationType) {
  final Retention retention = annotationType.getAnnotation(Retention.class);
  if (null == retention) {
    return RetentionPolicy.CLASS;
  }
  return retention.value();
}

代码示例来源:origin: square/retrofit

@Retention(RUNTIME)
@interface Json {
@Retention(RUNTIME)
@interface Xml {

代码示例来源:origin: looly/hutool

/**
 * 获取注解类的保留时间,可选值 SOURCE(源码时),CLASS(编译时),RUNTIME(运行时),默认为 CLASS
 * 
 * @param annotationType 注解类
 * @return 保留时间枚举
 */
public static RetentionPolicy getRetentionPolicy(Class<? extends Annotation> annotationType) {
  final Retention retention = annotationType.getAnnotation(Retention.class);
  if (null == retention) {
    return RetentionPolicy.CLASS;
  }
  return retention.value();
}

代码示例来源:origin: square/retrofit

@Retention(RUNTIME) public @interface Moshi {
@Retention(RUNTIME) public @interface Gson {
@Retention(RUNTIME) public @interface SimpleXml {

代码示例来源:origin: com.google.inject/guice

private static void checkForRuntimeRetention(Class<? extends Annotation> annotationType) {
 Retention retention = annotationType.getAnnotation(Retention.class);
 checkArgument(
   retention != null && retention.value() == RetentionPolicy.RUNTIME,
   "Annotation %s is missing RUNTIME retention",
   annotationType.getSimpleName());
}

代码示例来源:origin: CarGuo/GSYVideoPlayer

/**
 * Created by yhao on 2017/12/23.
 * https://github.com/yhaolpz
 */

public class Screen {
  public static final int width = 0;
  public static final int height = 1;

  @IntDef({width, height})
  @Retention(RetentionPolicy.SOURCE)
  @interface screenType {
  }
}

代码示例来源:origin: facebook/litho

/**
  * We consider an annotation to be valid for extraction if it's not an internal annotation (i.e.
  * is in the <code>com.facebook.litho</code> package and is not a source-only annotation.
  *
  * @return Whether or not to extract the given annotation.
  */
 private static boolean isValidAnnotation(AnnotationMirror annotation) {
  final Retention retention =
    annotation.getAnnotationType().asElement().getAnnotation(Retention.class);

  if (retention != null && retention.value() == RetentionPolicy.SOURCE) {
   return false;
  }

  return !annotation.getAnnotationType().toString().startsWith("com.facebook.");
 }
}

代码示例来源:origin: CarGuo/GSYVideoPlayer

/**
 * Created by yhao on 2017/12/22.
 * https://github.com/yhaolpz
 */

public class MoveType {
  static final int fixed = 0;
  public static final int free = 1;
  public static final int active = 2;
  public static final int slide = 3;
  public static final int back = 4;

  @IntDef({fixed, free, active, slide, back})
  @Retention(RetentionPolicy.SOURCE)
  @interface MOVE_TYPE {
  }
}

代码示例来源:origin: apache/incubator-dubbo

RetentionPolicy retentionPolicy = retention.value();

代码示例来源:origin: jenkinsci/jenkins

/**
 * Marker interface that designates extensible components
 * in Jenkins that can be implemented by plugins.
 *
 * <p>
 * See respective interfaces/classes for more about how to register custom
 * implementations to Jenkins. See {@link Extension} for how to have
 * Jenkins auto-discover your implementations.
 *
 * <p>
 * This interface is used for auto-generating
 * documentation.
 *
 * @author Kohsuke Kawaguchi
 * @see Plugin
 * @see Extension
 */
public interface ExtensionPoint {
  /**
   * Used by designers of extension points (direct subtypes of {@link ExtensionPoint}) to indicate that
   * the legacy instances are scoped to {@link Jenkins} instance. By default, legacy instances are
   * static scope.  
   */
  @Target(TYPE)
  @Retention(RUNTIME)
  @interface LegacyInstancesAreScopedToHudson {}
}

代码示例来源:origin: apache/incubator-dubbo

RetentionPolicy retentionPolicy = retention.value();

代码示例来源:origin: yhaolpz/FloatWindow

/**
 * Created by yhao on 2017/12/23.
 * https://github.com/yhaolpz
 */

public class Screen {
  public static final int width = 0;
  public static final int height = 1;

  @IntDef({width, height})
  @Retention(RetentionPolicy.SOURCE)
  @interface screenType {
  }
}

代码示例来源:origin: redisson/redisson

/**
 * {@inheritDoc}
 */
public RetentionPolicy getRetention() {
  AnnotationDescription.Loadable<Retention> retention = getAnnotationType().getDeclaredAnnotations().ofType(Retention.class);
  return retention == null
      ? RetentionPolicy.CLASS
      : retention.loadSilent().value();
}

代码示例来源:origin: zaaach/CityPicker

public class LocateState {
  public static final int LOCATING    = 123;
  public static final int SUCCESS     = 132;
  public static final int FAILURE     = 321;

  @IntDef({SUCCESS, FAILURE})
  @Retention(RetentionPolicy.SOURCE)
  public @interface State{}
}

代码示例来源:origin: google/guava

rootLocaleFormat("%s must have RUNTIME RetentionPolicy.", annotationClass),
  RetentionPolicy.RUNTIME,
  retentionPolicy.value());
assertNotNull(
  rootLocaleFormat("%s must be inherited.", annotationClass),

相关文章