java - Why Object class have static block? -


i want know why object,string etc. have static{} block @ end.what use of static block in object class.

open cmd prompt , type

javap java.lang.object 

enter image description here

what looking @ method , field declarations. since static block method, see empty declaration of static-initalizer.

if @ openjdk source code java.lang.object on line 40, code says

public class object {       private static native void registernatives();      static {          registernatives();      } 

a simple explanation of static block block gets called once, no matter how many objects of type create.


if want more information command line, javap -verbose java.lang.object outputs this

  static {};     descriptor: ()v     flags: acc_static     code:       stack=0, locals=0, args_size=0          0: invokestatic  #16                 // method registernatives:()v          3: return       linenumbertable:         line 41: 0         line 42: 3 } 

or, less verbose javap -c java.lang.object

  static {};     code:        0: invokestatic  #16                 // method registernatives:()v        3: return 

if want read registernatives() does, can read post.

what registernatives() method do?


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -