java - Why are private inner classes not visible for static imports? -
i defined private inner enum class , tried static import 1 of enum values this:
public class outerclass { private enum innerenum { one, 2 } public static void main(string... args) { system.out.print(one); } }
this not possible because static import statement shown below not visible:
import static outerclass.innerenum.one;
i had widen visibility private
package private
make work. know semantic of private
point why same code, once written qualified enum value this:
system.out.print(innerenum.one);
is valid written this:
import static outerclass.innerenum.one; ... system.out.print(one);
is not. java import statement (static or not) introduces alias. private types not allowed introduce alias. seams weird me.
does know language design decision behind restriction?
which risk or danger occur allowing static import in case?
i hardly interested in technical motivated reasons.
the idea behind private class in class can see it. gets useful if program collection or more general structure , dont want other classes see structure. private useful securing no other classes able manipulate values or structures in class. in nutshell private hiding , securing structures , variables.
Comments
Post a Comment