File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tricky Class Name..?

 
anand phulwani
Ranch Hand
Posts: 242
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • 0
  • Mark post as helpful
  • send pies
  • 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: 242
  • 0
  • Mark post as helpful
  • send pies
  • 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: 2068
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic