maresa
maresa

Reputation: 641

What does $("something") mean in Java?

I was looking into some tutorial and stumbled on this code:

public void run(String... args) throws Exception {
    eventBus.on($("quotes"), receiver);
    publisher.publishQuotes(NUMBER_OF_QUOTES);
}

This is the first time I see $("quotes") in Java. I'd appreciate someone explaining to me what's going on there.

Here's the source:

https://github.com/spring-guides/deprecate-gs-messaging-reactor/blob/master/complete/src/main/java/hello/Application.java#L53

Update:

This is not a question about $ as Java variable name. I know that it's a valid variable name. However, the format of $("something") looks JQuery-like; hence threw me off thinking that it's a special directive or something.

Upvotes: 3

Views: 1685

Answers (2)

user85421
user85421

Reputation: 29680

it is just a call to the method called $ that is statically imported:

import static reactor.bus.selector.Selectors.$;

it is just a normal method with a strange name.

'$' is a valid character for identifiers according the 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.

Upvotes: 4

Elliott Frisch
Elliott Frisch

Reputation: 201447

You have an import static reactor.bus.selector.Selectors.$;

From the documentation that is a short-hand alias for object(T) which in turn creates a Selector based on the given object.

Upvotes: 4

Related Questions