Reputation: 33
What is the difference or significance of putting $ sign before any variable or parameter..
e.g.
Suppose here is my class...
public class Vector3 {
public Vector3(float x, float y, float z){
//...
//... my ctor code
//...
}
}
and what will be the difference between these two declarations...
Declaration 1
Vector3 $vec = new Vector3(1f,1f,1f);
Declaration 2
Vector3 vec = new Vector3(1f,1f,1f);
If you can notice $ sign before "vec" in Declaration 1 and Declaration 2.
Any clues?
Also, declaring the same constructor as below,
public class Vector3 {
public Vector3(float $x, float $y, float $z){
//...
//... my ctor code
//...
}
}
What is difference between above constructor and the initial constructor ?
Thanks...
Edit: Thanks to all your responses, I did this with different combinations and there is no major significance :) I appreciate all your answers.
Upvotes: 3
Views: 5346
Reputation:
While many people have pointed out that $
is legal in identifiers, I refute the use of $
(at least as an initial token) as it goes against the Java Naming Conventions:
Variable names should not start with underscore _ or dollar sign $ characters, even though both are allowed.
While this does not include the case of foo$bar
I follow the JLS recommendation that the $
be used only in generated code. The Java compiler uses $
when it generates anonymous classes, for instance.
If nothing else, I would consider your code ugly :-)
Upvotes: 7
Reputation: 45433
compiles and runs. kid you not.
package $;
public class $
{
int $;
int $(int $){ return $; }
void $$(int $){ this.$=$; }
$ _(){ return this; }
$ _;
{
$$($($));
_._()._._()._();
}
}
Upvotes: 13
Reputation: 315
I don't believe it is anything more than a valid symbol for use in Java variable names. From the Java tutorial on variables ( http://download.oracle.com/javase/tutorial/java/nutsandbolts/variables.html ):
Variable names are case-sensitive. A variable's name can be any legal identifier — an unlimited-length sequence of Unicode letters and digits, beginning with a letter, the dollar sign "$", or the underscore character "_". The convention, however, is to always begin your variable names with a letter, not "$" or "_". Additionally, the dollar sign character, by convention, is never used at all. You may find some situations where auto-generated names will contain the dollar sign, but your variable names should always avoid using it. A similar convention exists for the underscore character; while it's technically legal to begin your variable's name with "_", this practice is discouraged. White space is not permitted.
Upvotes: 3
Reputation: 48369
According to the Java Language Specification, it's permissible, but has no special meaning. Note that the specification goes on to recommend that it "only be used in mechanically generated source code, or rarely, to access pre-existing names in a legacy system".
Upvotes: 11
Reputation: 59
Variable names are case-sensitive. A variable's name can be any legal identifier — an unlimited-length sequence of Unicode letters and digits, beginning with a letter, the dollar sign "$", or the underscore character "". The convention, however, is to always begin your variable names with a letter, not "$" or "". Additionally, the dollar sign character, by convention, is never used at all. You may find some situations where auto-generated names will contain the dollar sign, but your variable names should always avoid using it. A similar convention exists for the underscore character; while it's technically legal to begin your variable's name with "_", this practice is discouraged. White space is not permitted.
Taken from : ttp://download.oracle.com/javase/tutorial/java/nutsandbolts/variables.html#naming
Upvotes: 0