• Post Reply Bookmark Topic Watch Topic
  • New Topic

variable prefiexed with $ symbol  RSS feed

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I wrote the following code and test what would be the compilation errors. I found strange message. Anybody can answer why it was so?
code:
class Example
{
public static void main(String args[])
{
int $num;
$nume = 100; // variable name is changed purposely.
System.out.println(" The value of $num is " + $num);
}
}
Compile time error message:
Example.java:6:cannot resolve sysmbol
symbol: variable $nume
location: class Example
perhaps it meant .nume
$nume = 100;
^
My doubt:
1. Is that any special meaning for $var_name
2. What it meant by the message "perhaps it meant .var_name"
with regards,
balaji
 
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

1. Is that any special meaning for $var_name

No.

2. What it meant by the message "perhaps it meant .var_name"

Looks like the compiler is just trying to be helpful.
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you change $nume to $num, it compiles and runs just fine, at least under JBuilder 9 using JDK 1.4.1.
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before you decompiled the code, it was an inner class.
I suggest you do the ethical and moral thing, and ask the author for the source.
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
It's quite straightforward. You defined a variable called $num.
You then, "on purpose" try to use a variable called $nume which you never
defined. The compiler can't find it, and suggests that you might wanted to
use a different name. For some reason it suggested nume and not $num.
a $ is a perfectly legal character to use in Java identifiers. You can, if you wish define a variable int $ = 0;
However, this is not very readable.
As for the decompiling hint - Had it been an inner class the name would be something like Outer$Inner and not just $Inner. No need for flames where there's no coal.

Nimo.
 
Alangudi Balaji Navaneethan
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jason Fox:
If you change $nume to $num, it compiles and runs just fine, at least under JBuilder 9 using JDK 1.4.1.

I know it. But I did it purposely to know what kind of error message it gives. I am using jdk1.4.2 downloaded from sun portal.
 
Alangudi Balaji Navaneethan
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tony Morris:
Before you decompiled the code, it was an inner class.
I suggest you do the ethical and moral thing, and ask the author for the source.

I am the author of this code. I purposely changed the variable name to differ from the declared one and looked for the error message. But I got strange message like the one I posted only for the variable prefixed with $.
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A lot of people in this thread are missing the point. The point is that javac doesn't normally suggest alternatives when it finds an unknown name, but in this one small corner case, it does. Furthermore, the message it uses to make this suggestion is weird: javac 1.4.2 says

If you're not a native English speaker, you might not realize the word "perchance" is a very old-fashioned word meaning "maybe." Nobody ever says this word out loud; you'll see it in Shakespeare's writings, but not normally in compiler output!
I think what's happened is that you've stumbled on a little bit of development code that wasn't supposed to be in the release. Perhaps a developer was fooling around with the idea of having javac make suggestions the way that the jikes compiler does, and removed most of that code before the release, but forgot this one little piece of it.
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Off topic. But most people who come from countries which were colonised by the English would understand what perchance means. Even today.
Other than that, it is a good find on the debug message.
 
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's easy to decompile as 'per chance', but I'm happy to know your compiler speaks Shakespear's english.
javac-1.5:linux doesn't.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!