Java =+;和+=
两种符号之间的区别是什么:Java =+;和+=,java,Java,两种符号之间的区别是什么: encryText =+ text; 及 注意:encryText和text都是字符串 可以解释为 encryText = +text; // positive(text) assigned to encryText 及 可以解释为 encryText = encryText + text; // encryText is added with text and assigned back to encryText encryText = encryText +
encryText =+ text;
及
注意:encryText和text都是字符串
可以解释为
encryText = +text; // positive(text) assigned to encryText
及
可以解释为
encryText = encryText + text; // encryText is added with text and assigned back to encryText
encryText = encryText + text; // String concatenation happens here
正(文本)
-表示正整数。你只是在这里明确地指定了标志。通常,指定正整数时不带+
符号
1
-正数1(即使没有+
符号,也表示正整数1)
+1
-正数1,明确指定了+
符号(除明确的+
符号外,与上述符号没有任何区别)
-1
-负数1,需要使用-
符号指示其为负整数
编辑: 您编辑了您的问题,并完全更改了此处的上下文(这完全没有完成)。然而,如果两者都是字符串 可以解释为
encryText = encryText + text; // encryText is added with text and assigned back to encryText
encryText = encryText + text; // String concatenation happens here
及
encryText=+text代码>-将给您一个编译错误。不能对字符串本身使用+
。它不是可以在java中对字符串执行的有效操作
encryText =+ text;
不是有效代码,它将导致编译错误。
请参见区别在于=+在java规范中不是运算符()。java最可能做的就是将您的语句解释为
encryText=+text代码>(我不知道这能做什么)
但是它不会做任何与+=”相比较的事情。你所说的正赋值给encryText
是什么意思?…正(text)-表示正整数。你只是在这里明确地指定了标志“我不明白你的意思,但是一个正字符串意味着什么?你改变了你的问题。最初它并没有说两者都是字符串。你的权利,在你编辑后我删除了我的否决票+1在第一种情况下,您的代码无法编译。不能应用空字符串concat。encryText=+text
给出编译时错误。你试过了吗?在把答案贴到原来的问题上之后,请不要完全改变问题的上下文。如果它们应该是字符串,那么应该从一开始就在问题中提及,而不是在答案发布后作为编辑。
encryText = encryText + text; // String concatenation happens here
encryText =+ text;