• Post Reply Bookmark Topic Watch Topic
  • New Topic

private constructor code  RSS feed

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator





In preceding code why we are invoke getDeclaredConstructors() method on both HackMe and class (i.e HackMe.class)?please give me detailed explanation

[edit]Add code tags. CR[/edit]
[ December 19, 2008: Message edited by: Campbell Ritchie ]
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although on the surface this seems to be about an arguably advanced topic -- reflective access to private constructors -- I think it's actually a question about basic Java syntax and reading the API documents.

The syntax "HackMe.class" retrieves the java.lang.Class object that represents the HackMe class. It's a convenient shortcut to the same object returned by the static method call Class.forName("HackMe") . The method getDeclaredConstructors() is a method of java.lang.Class, and so we have to fetch the appropriate Class object to call the method on.
[ December 19, 2008: Message edited by: Ernest Friedman-Hill ]
 
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope we have made you welcome here, Raj Chiru

Please find the code button and maintain indentation. I have edited your post to add indentation, and you can see how much better it looks.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!