• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how about the class names as a$b?

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
following code will compile, but how to distinguish these two class?
class t9$b
{
public static void main(String argv[]){
System.out.println("ABC");
}
}
class t9
{
class b{ }
}
in mymachine, the only t9$b.class file is class b in t9 class.
so 'java t9$b' will not print the string "ABC"
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Classes containing the character '$' are usually reserved for the compiler. Technically, they are legal, but your compiler uses the '$' to designate anonymous inner classes. I would advise agains this naming convention, and then you won't have to worry about which is which.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I tried this using JDK 1.3, the compiler comlained the class t9$b was defined twice. I believe this is actually a bug in the compiler - this construction should be legal, but as Bodie says, it isn't a good idea.
 
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The $ symbol is used to designate ALL inner classes - not just anonymous inner classes. An anonymous class in MyClass would be called MyClass$1. A class called 'InnerLad' in MyClass would be called MyClass$InnerLad.

Originally posted by Bodie Minster:
Classes containing the character '$' are usually reserved for the compiler. Technically, they are legal, but your compiler uses the '$' to designate anonymous inner classes. I would advise agains this naming convention, and then you won't have to worry about which is which.


 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Per the JLS:


The $ character should be used only in mechanically generated source code or, rarely, to access preexisting names on legacy systems.


So using the $ in the Class name is not proper anyway.
[This message has been edited by Cindy Glass (edited March 23, 2001).]
reply
    Bookmark Topic Watch Topic
  • New Topic