java - Should the constructor of a private inner class be declared public or private? -


is there actual difference between this

public class outerclass {     private class innerclass {         public innerclass() {}     } } 

and this?

public class outerclass {     private class innerclass {         private innerclass() {}     } } 

accessing private members class more complicated because jvm doesn't allow this. result compiler injects accessor methods makes slower or stack trace more complicated.

for these reason leave package local.

btw constructor of abstract class doesn't need public either. may protected or package local

private static class {     private a() {         throw new error();     } } public static void main(string... ignored) {     new a(); } 

prints stack trace element.

exception in thread "main" java.lang.error     @ main$a.<init>(main.java:8)     @ main$a.<init>(main.java:6)     @ main.main(main.java:12) 

make constructor package local , second 1 disappears.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -