接口内的androidx stringdef值

qaxu7uf2  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(163)

我目前正在用androidx的stringdef替换一些枚举,查看我注意到他们这样使用的文档:

@Retention(SOURCE)
  @StringDef({
     POWER_SERVICE,
     WINDOW_SERVICE,
     LAYOUT_INFLATER_SERVICE
  })
  public @interface ServiceName {}
  public static final String POWER_SERVICE = "power";
  public static final String WINDOW_SERVICE = "window";
  public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";

在我目前的情况下,我想在父类中声明多个stringdef。为了结构和代码的整洁,在@interface中声明值而不是像这样在外部声明值会有任何缺点:

@Retention(SOURCE)
    @StringDef({
            ServiceName.POWER_SERVICE,
            ServiceName.WINDOW_SERVICE,
            ServiceName.LAYOUT_INFLATER_SERVICE
    })
    public @interface ServiceName {
        String POWER_SERVICE = "power";
        String WINDOW_SERVICE = "window";
        String LAYOUT_INFLATER_SERVICE = "layout_inflater";
    }

这样做有什么坏处吗?这会不会遭到其他android开发者的反对,或者只是一个偏好问题?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题