What happens if you remove the space between the + and ++ operators?

偶尔善良 提交于 2019-12-05 05:13:15

Compiler generates longest possible tokens when parsing source, so when it encounters +++, it takes it as ++ +.

So the code of

a +++ b

Will always be same as

(a++) + b

There is no +++ operator. What you have there is a postfix ++ operator followed by an infix + operator. That is a compilation error because postfix ++ can only be applied to a variable, and "s " isn't a variable.

Since you really mean an infix + operator followed by a prefix ++ operator, you need to put the space in between the operators.

Actually, you should do it ANYWAY. +++ is a crime against readability!!!

The triple plus is not an operator itself, it is two operators combined:

What the triple plus acutually does is:

a+++1 == a++ + 1;

What you are trying to do is ++ a String, which is undefined.

Never ever use +++ without spaces in your code; hardly anyone will know what it does (without consulting web). Moreover, after a week or so, you will not know what it actually does yourself.

+++ isn't an operator by itself.

i = i +++i; results in a pre-increment value of i, then adding it to the value of i and storing it in i.

With the String, + doesn't mean addition, so you're attempting to concatenate the string and the integer together.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!