简体   繁体   English

Java如何将“逻辑和运算符”分配给“布尔变量”

[英]Java How to assign “Logical And Operator” to a “boolean variable”

It is just my curiosity whether I can do something like 我的好奇心是否可以做类似的事情

private static boolean and = &&;

I wonder whether a "logical and operator" can be assigned to a "boolean variable". 我想知道“逻辑和运算符”是否可以分配给“布尔变量”。

PS I can't compile the sentence, because it already gave an error. PS我无法编译句子,因为它已经给出了错误。 Since variable initialization requires tokens and && is not a token. 由于变量初始化需要令牌,而&&不是令牌。

You can't do this in Java. 你不能用Java做到这一点。 If you have your heart set on doing something like this, try using the preprocessor command #define in C or C++. 如果您已经开始做这样的事情,请尝试在C或C ++中使用预处理器命令#define

Beware though - this is NOT recommended as you'll have a lot of trouble debugging and finding other developers to work on code with you. 请注意 - 不建议这样做,因为您在调试和寻找其他开发人员处理代码时会遇到很多麻烦。

You may even end up with your own entry on TheDailyWTF (like this , this , this , this , or this ) 你甚至可能最终在TheDailyWTF上输入你自己的条目(就像这个这个这个这个或者这个

Here is an example using English grammar, the way I see it: 这是一个使用英语语法的例子,就像我看到的那样:

"And" and "True" are different parts of speech. “和”和“真实”是不同的词性。 "True" is an adjective, so you can say, "That is true." “真实”是一个形容词,所以你可以说,“这是真的。” "And" is a conjunction, so it does not make sense to say "That is and." “和”是一种结合,所以说“那是和”是没有意义的。

Same thing with && and true . &&true相同的事情。 && is an operator "part of speech," whereas true is a value "part of speech." &&运营商的 “语言的一部分”,而true价值是 “言论的一部分”。 Because of this, it doesn't make sense to set a boolean value to an operator . 因此,将boolean 设置为运算符是没有意义的。 Perhaps something like this could be done, if instead of boolean and = && you could type BooleanOperator and = && ; 也许这样的事情可以完成,如果不是boolean and = &&你可以输入BooleanOperator and = && ; however, there is no such type or functionality in Java (see Chris's answer about C). 但是,Java中没有这样的类型或功能(参见Chris关于C的答案)。

For years people have wanted sentence like programming. 多年来人们一直想要编程之类的句子。 If you can make a language that does that, then awesome! 如果你能用一种语言来做,那真棒! However java cannot be converted to sentence like programming. 但是java不能像编程一样转换成句子。 Perhaps you could write a string modifying class that assigns certain words to other characters that it would then input into whatever text editor you are using. 也许您可以编写一个字符串修改类,将某些单词分配给其他字符,然后将其输入到您正在使用的任何文本编辑器中。 Good luck debugging though! 祝你好运调试!

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

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