[英]Why do these two code fragments differ
I just noticed that when I change the last line in the code fragment from potential =+ rep_pot
to potential = potential + rep_pot
, I get completely different behaviour. 我只是注意到,当我将代码片段的最后一行从potential =+ rep_pot
为potential = potential + rep_pot
,我得到了完全不同的行为。 Has anybody got any idea why this is happening? 有人知道为什么会这样吗?
double potential = euclideanDistance(i, goal);
for (IntPoint h: hits){
double dist = euclideanDistance(i, h);
double a = range - dist;
double rep_pot = (Math.exp(-1/a)) / dist;
potential =+ rep_pot;
}
There is no =+
operator in Java. Java中没有=+
运算符。 See the Java Language Specification for all legal operators. 有关所有合法运算符,请参见Java语言规范 。
=+
are two operators: =
followed by +
. =+
是两个运算符: =
后跟+
。
That is because 那是因为
potential = potential + rep_pot
is similar to 类似于
potential += rep_pot
and 和
potential =+ rep_pot;
is the same as 是相同的
potential = rep_pot;
You probably meant +=
. 您可能是说+=
。 In your case it is interpreted as x = +x
which is x = x
在您的情况下,它被解释为x = +x
,即x = x
Use +=
: 使用+=
:
potential += rep_pot;
Yes, because these two things are not equivalent. 是的,因为这两件事并不等同。
potential =+ rep_pot;
Here we have potential assigned a value of the expression 'unary plus rep_pot' 在这里,我们可能为表达式分配了一个值'unary plus rep_pot'
The thing you intendet to write looks differently: 您打算写的东西看起来有所不同:
potential += rep_pot;
And this is equivalent to 这相当于
potential = potential + rep_pot;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.