What is this expression in Java ( 1 << 2)?

后端 未结 2 649
慢半拍i
慢半拍i 2021-01-19 08:07

I don\'t know what this means \"1 << 2\" in :

public static final int MODIFY_METADATA = 1 << 2; // modify object

Please help m

2条回答
  •  一生所求
    2021-01-19 09:05

    If you want to know why would use use 1 << 2 rather than 4 which is the same value, it because you explicitly want to be using a bit mask e.g.

    public static final int FLAG0 = 1 << 0;
    public static final int FLAG1 = 1 << 1;
    public static final int MODIFY_METADATA = 1 << 2;
    

    Shows each value is in a bit mask.

提交回复
热议问题