interface 里是可以定义变量的
https://docs.oracle.com/javase/specs/jls/se8/html/jls-9.html#d5e15029
打开这个地址后稍微往后拖一点就可以看到例子了。
这个是 Oracle 的官方文档。
- interface BaseColors {
- int RED = 1, GREEN = 2, BLUE = 4;
- }
- interface RainbowColors extends BaseColors {
- int YELLOW = 3, ORANGE = 5, INDIGO = 6, VIOLET = 7;
- }
- interface PrintColors extends BaseColors {
- int YELLOW = 8, CYAN = 16, MAGENTA = 32;
- }
- interface LotsOfColors extends RainbowColors, PrintColors {
- int FUCHSIA = 17, VERMILION = 43, CHARTREUSE = RED+90;
- }
复制代码
|