| Author |
how to see the <init> instance initialization method ?
|
gurpeet singh
Ranch Hand
Joined: Apr 04, 2012
Posts: 892
|
|
|
i have read that for each constructor there is instance initialization method whose name is <init> and return type is void. i would like to know is there any way to view those instance initialization methods generated from the source file using any tool/command-line or perhaps through IDE?
|
OCPJP 6(100 %) OCEWCD 6(91 %)
|
 |
John Jai
Bartender
Joined: May 31, 2011
Posts: 1778
|
|
I am not aware of this concept, but can see a <init> and an empty return when I use javap -c option.
Java class:
javap output:
|
 |
gurpeet singh
Ranch Hand
Joined: Apr 04, 2012
Posts: 892
|
|
|
thanks for the reply John. i read an article on object initialization at http://www.javaworld.com/javaworld/jw-03-1998/jw-03-initialization.html?page=5 . i liked it alot. lets wait for other ranchers if there is any way to view the <init> methods.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16811
|
|
Not really adding anything to this discussion -- but just want to mention.... that all of these years of using / debugging with Java (and working with lots of stacktraces), I have never thought that there was an "<init>" method. I just thought that is how the stacktrace code shows that you are in constructor code. Oh well.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 3860
|
|
Henry Wong wrote:
Not really adding anything to this discussion -- but just want to mention.... that all of these years of using / debugging with Java (and working with lots of stacktraces), I have never thought that there was an "<init>" method. I just thought that is how the stacktrace code shows that you are in constructor code. Oh well.
I'd have probably thought the same way, but I was looking something up earlier to today (related to another question here) that made me realise it is real: if you look at
java.lang.Class#getMethod(java.lang.String, java.lang.Class...) you can see that <init> is treated as a special case (i.e. it's a method, but that method will pretend it isn't).
|
 |
gurpeet singh
Ranch Hand
Joined: Apr 04, 2012
Posts: 892
|
|
|
thanks for the information guys. but if the <init> method is real, which it is then there should be some way to see it ? the original question is still yet to be answered/
|
 |
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 3860
|
|
|
It's real in the byte-code. So the only way to see it is with a byte-code viewer, which is what John showed.
|
 |
 |
|
|
subject: how to see the <init> instance initialization method ?
|
|
|