• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

fully qualified name of nested class

 
Ranch Hand
Posts: 209
13
VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In this code, I have a static nested class Dog.

output:

Within main of the outer class, I'm using Class.forName() to get a class literal and then using that class literal to create a Dog.
At line 12, the dog proves it really is a Dog, by barking.
What seems odd is that, the String I supply as argument to Class.forName() must be "ClassLiteralTest$Dog".
I know that on compilation a .class file with $ separated name is generated, but elsewhere in code, if I want to refer to or create a Dog, as at line 17, I'd use dot syntax. Similarly, Dog.class.getCanonicalName() returns a dot separated name.

So, is the way to understand this, that the fully qualified name of a class, as required by Class.forName(), is the name in the host os file system less '.class', which isn't always the same as the canonical name?


 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Richard Hayward wrote:What seems odd is that, the String I supply as argument to Class.forName() must be "ClassLiteralTest$Dog".


That's not odd, that's just how it works More info can be found in this topic.
 
Richard Hayward
Ranch Hand
Posts: 209
13
VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roel De Nijs wrote:More info can be found in this topic.


Thanks Roel, I'll study that thread.
 
What's a year in metric? Do you know this metric stuff tiny ad?
ScroogeXHTML - fast RTF to HTML and XHTML conversion
https://coderanch.com/t/749563/ScroogeXHTML-fast-RTF-HTML-XHTML
reply
    Bookmark Topic Watch Topic
  • New Topic