Java使用什么技巧来避免在>> ;?中的空格 [英] What trick does Java use to avoid spaces in >>?
问题描述
在Java通用书中,虽然对比了C ++模板和Java泛型之间的区别:
In the Java Generic Book, while contrasting the difference between C++ Templates and Java Generic says:
在C ++中, >>
无空格表示
右移运算符。 Java
In C++, a problem arises because >> without the space denotes the right-shift operator. Java fixes the problem by a trick in the grammar.)
这个技巧是什么?
推荐答案
这实际上是在下一个版本的C ++中修复。真的没有太多的窍门;如果在解析一个泛型或模板的过程中遇到了>>,而您希望>,那么您已经有足够的信息来生成错误消息。而且,如果您有足够的信息生成错误消息,您也有足够的信息来解释>>为两个单独的令牌:>后跟>。
This is actually being fixed in C++ in the next version. There really isn't much of a trick; if you encounter >> while in the process of parsing a generic or template where instead you expected >, then you already have enough information to generate an error message. And, if you have enough information to generate an error message, you also have enough information to interpret >> as two separate tokens: > followed by >.
这篇关于Java使用什么技巧来避免在>> ;?中的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!