我在查看一些教程时偶然发现了这段代码:
public void run(String... args) throws Exception {
eventBus.on($("quotes"), receiver);
publisher.publishQuotes(NUMBER_OF_QUOTES);
}
这是我第一次在 Java 中看到 $("quotes")
。如果有人向我解释那里发生了什么,我将不胜感激。
这是来源:
更新:
这不是关于 $ 作为 Java 变量名的问题。我知道这是一个有效的变量名。但是,$("something") 的格式看起来像 JQuery;因此让我不再认为这是一个特殊指令或其他东西。
最佳答案
它只是调用静态导入的名为 $
的方法:
import static reactor.bus.selector.Selectors.$;
这只是一个普通的方法,名字奇怪。
'$' 是根据 Java Language Specification 3.8 的标识符的有效字符
The "Java letters" include uppercase and lowercase ASCII Latin letters A-Z (\u0041-\u005a), and a-z (\u0061-\u007a), and, for historical reasons, the ASCII underscore (_, or \u005f) and dollar sign ($, or \u0024). The $ sign should be used only in mechanically generated source code or, rarely, to access pre-existing names on legacy systems.
关于java - $ ("something") 在 Java 中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43150564/