Dust
Dust

Reputation: 21

What is the $ in Syntactic sugar of Java?

//source code 
int[] s = new int[]{1,2,3,4};
for(int i:s){
    System.out.println(i);
}
----------------------------
//below is in the class file 
for(int i$ = 0; i$ < b; ++i$) {
    int i = a[i$];
    System.out.println(i);
}

what's the use of the $? i$ is a pointer like c?

Upvotes: 0

Views: 507

Answers (1)

Elliott Frisch
Elliott Frisch

Reputation: 201409

In this case, it is literally a variable named i$. JLS-3.8. Identifiers reads (in part)

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: 5

Related Questions