I recently saw the source code of the Google library Gson and saw something really strange (IMO). In the com.google.gson.internal package there are 2 classes which do begin with a "$".
For example
public final class $Gson$Types { ... }
Does the dollar sign has a effect to development or is it just to say to outside developers something like "please don't use cause it is a internal class"?
You can use any currency sign or continuation character in an identifier.
By using $, it suggests it is generated e.g. generated by the build, or for internal use only.
Uses for special characters in Java code
Hidden code
It only causes a problem if you have conflicts with generated classes e.g.
class A {
class B {
}
}
class A$B {
}
reports
error: duplicate class: A.B
Compiler generated classes do not start with a $
which may be reason this as done.
On Windows 7, the special characters which can appear in a Class are
public static void main(String... args) throws IOException {
for (char ch = 0; ch < Character.MAX_VALUE; ch++) {
if (Character.isJavaIdentifierStart(ch) && !Character.isLetter(ch))
System.out.println("interface " + ch + " { }");
}
}
interface $ { }
interface _ { }
interface ¢ { }
interface £ { }
interface ¤ { }
interface ¥ { }
interface € { }
Other special characters are allows by Java, but not supported as file names. This may depend on the OS and possibly the language.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With