简体   繁体   English

操作员| 对于int值

[英]operator | for int value

I think this is a basic in java, but sorry, I ask in stackoverflow. 我认为这是Java的基本知识,但是抱歉,我在stackoverflow中询问。

I will give an example in eclipse RCP. 我将在Eclipse RCP中举一个例子。 For example, if I want to make instance of Text (swt text), I would do below: 例如,如果要创建Text(swt文本)的实例,请执行以下操作:

Text text = new Text(composite, SWT.BORDER | SWT.MULTI);

In second parameter Text, it is a int style, and I would the text will be border and can be multi line, so I add SWT.BORDER | 在第二个参数Text中,它是一种int样式,我希望文本将是border并可以是多行,因此我添加了SWT.BORDER | SWT.MULTI (the operator | will be used). SWT.MULTI(将使用运算符|)。

Now the question, for example I add already have a variable int style by the method getStyle() in the Text class. 现在的问题,例如我通过Text类中的getStyle()方法添加的int样式已经可变。 But I want to check if the SWT.MULTI is already set or not, how can I archive it? 但是我想检查SWT.MULTI是否已设置,如何归档? Thanks 谢谢

bool multiIsSet = (x & SWT.MULTI) == SWT.Multi

Your solution is the bitwise & operator. 您的解决方案是按位&运算符。

if (myText.getStyle() & SWT.MULTI){
 //whatever
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM