2

Silly question I know but in the google gson library I see this code:

import com.google.gson.internal.$Gson$Types;

in TypeToken.java

and references to this $Gson$Types thing. It appears as a syntax error. Is this $ just an allowed character for names of objects in Java?

sproketboy
  • 8,967
  • 18
  • 65
  • 95
  • `$` is simply a legal character for symbols, like `T`, but is "reserved" and (by convention) only to be used by the compiler, et al. – Hot Licks Sep 04 '14 at 11:20

2 Answers2

3

It's allowed, but Eclipse IDE for instance tells you using it in Class name is discourage.

I believe that main reason for that being discourage is that binary name to inner class using convention of $ for instance

class A {
    class B {
    }
}

Binary name would look something like <somepackage>.A$B. Nevertheless it doesn't matter since it's start from $ in your particular case and therefor it's unique.

abc
  • 2,371
  • 3
  • 25
  • 36
1

Yes, $ is a legal first letter for variables. However it is strongly discouraged to do this.

Assaf
  • 1,352
  • 10
  • 19