• 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

Tricky Class Name..?

 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can anyone explain me about this...

test22.java:13: duplicate class: test22.abc
class abc
^
test22.java:25: cannot find symbol
symbol : class abc
location: class test22
test22.abc x=me.new abc();
^
test22.java:25: cannot find symbol
symbol : class abc
location: class test22
test22.abc x=me.new abc();
^
3 errors[CODE]

Thanx
 
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
above, you defined

class test22$abc{
public test22$abc()
{
System.out.println("Outer");
}}


Your inner class will have exactly same name, so its a duplicate. test22$abc will be the compiled name of the inner class.
 
anand phulwani
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI, thanx for you reply

but could you please elaborate watz going on behind the scenes..

thanx
 
Jesus Angeles
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
as you already probably know,

the inner class is compiled into its very own class file

its name is Outerclassname plus '$' plus Innerclassname plus '.class'

so in your case, your inner class will be compiled to test22+$+abc+.class

ending up as test22$abc.class

exactly same as your other class

so its a duplicate
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the Java Language Specification (JLS) 3rd Edition: "The $ character should be used only in mechanically generated source code or, rarely, to access preexisting names on legacy systems."

The Java compiler generates nested class names containing $, so programmers should definitely avoid using it in class names. Within string literals or as a character to be input, processed, and output, the appearance of '$' is perfectly normal.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic