¿Cuál es la importancia de poner el signo "$" antes de un parámetro en Java / Android?

What is the difference or significance of putting $ sign before any variable or parameter..

p.ej

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...

Declaración 1

 Vector3 $vec = new Vector3(1f,1f,1f);

Declaración 2

 Vector3 vec = new Vector3(1f,1f,1f);

If you can notice $ sign before "vec" in Declaration 1 and Declaration 2.

¿Alguna pista?

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 ?

Gracias...

Edit: Thanks to all your responses, I did this with different combinations and there is no major significance :) I appreciate all your answers.

preguntado el 08 de enero de 11 a las 22:01

Where did you see that? If it's allowed (which I don't know) it may just be an old habit of PHP programmers. -

In that code they are using C#'s conventions for interface naming and naming private fields. And PHP's convention on naming variables. It's pretty ugly mutant, I don't understand why someone needs to update very clear and brilliant java naming conventions. -

after a lot of exercise, I found something really interesting about this framework, he is trying to segregate "Managed" and "UnManaged" vectors and 3d co-ordinates by "$" sign. I have already emailed him to get the concrete meaning of this million "$" sign. -

5 Respuestas

Según el Especificación del lenguaje Java, 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".

Respondido el 09 de enero de 11 a las 02:01

+1 Yay, I couldn't find the link about the "recommended" bit. - user166390

compiles and runs. kid you not.

package $;

public class $
{
    int $;

    int $(int $){ return $; }
    void $$(int $){ this.$=$; }

    $ _(){ return this; }

    $ _;

    {
        $$($($));

        _._()._._()._();
    }
}

Respondido el 09 de enero de 11 a las 02:01

of course it is compilable, but it is so funny xD haha the dollar sign and underscore looks like operator so it may confuse people hehehe - mínimo máximo promedio

It is an interesting piece of code, showing the extreme of java. - Satyendra

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 $ ser usado only in generated code. The Java compiler uses $ when it generates anonymous classes, for instance.

If nothing else, I would consider your code ugly :-)

Respondido el 21 de junio de 16 a las 13:06

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.

Respondido el 09 de enero de 11 a las 02:01

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

Respondido el 09 de enero de 11 a las 02:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.