使用注解代替枚举
程序员文章站
2022-05-21 09:17:18
...
相关的注解为IntDef和StringDef
public class AppConstant {
public static final int AWAIT = 0;
public static final int ING = 1;
public static final int FINISH = 2;
@IntDef({ AWAIT,ING,FINISH})
public @interface DoorState{}
}
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init(AppConstant.AWAIT);
}
private void init(@AppConstant.DoorState int a) {
System.out.println(a);
}
}
上一篇: clojure-基本语法-集合(一)