首页 > 解决方案 > 是否有任何 @MustCall 注释或如何强制使用注释为新对象调用方法?

问题描述

我知道@CheckResult注释和抽象方法。但我的需求略有不同。

    Class MyCustomAlert {
       /* blah blahs */

       @MustCall
       public void show() {
          // this method shows the dialog  
       }

    }

    ...
    MyCustomAlert alert = new MyCustomAlert();
    ...

现在我想要的是,lint(Android 工作室)应该像“ You forgot to call method 'show()'”一样警告我

这意味着MyCustomAlert类的每个新对象都必须调用该方法show()

android中是否有任何@MustCall或类似的注释?

标签: javaandroidannotationslint

解决方案


推荐阅读