3

What does dollar sign mean in variable names during debugging Java in InteliJ ? Is it a closure ? Please see the image and code snippet below.

Here is part of the Stream class:

public final Listener listen(final Handler<A> action) {
    return listen_(Node.NULL, new TransactionHandler<A>() {
        public void run(Transaction trans2, A a) {
            action.run(a);
        }
    });
}

I suspect that the $1 in Stream$1@915 refers to the closure created in the method above. I am not sure though. Can someone confirm this ? Or if that is not the case, explain what the dollar sign means in this generated name ?

The code is taken from the Sodium Functional Reactive library which I am trying understand how it works.

enter image description here

jhegedus
  • 18,516
  • 11
  • 84
  • 147
  • 1
    Possible duplicate of [java compiled classes contain dollar signs](http://stackoverflow.com/questions/11388840/java-compiled-classes-contain-dollar-signs), also maybe [What is the meaning of $ in a variable name?](http://stackoverflow.com/questions/7484210/what-is-the-meaning-of-in-a-variable-name). – Radiodef Feb 11 '15 at 02:04
  • Thanks ! I searched for answers on SOF but found nothing, perhapsI was searching with the wrong keywords. – jhegedus Feb 11 '15 at 14:44

1 Answers1

6

It's a reference to the anonymous inner class thats generated by this closure like construct. In general, inner classes are compiled and the class file name will be yourClassName$yourInnerClassName. In the case of an anonymous inner class declaration, since you don't name it explicitly, it will appear as a generated name using numbers. Perhaps this article will help?

Amir Afghani
  • 35,568
  • 16
  • 81
  • 120