java - Can a Static Nested Class be Instantiated Multiple Times? -


given know of every other type of static feature of programming––i think answer 'no'. however, seeing statements outerclass.staticnestedclass nestedobject = new outerclass.staticnestedclass(); makes me wonder.

yes, there nothing in semantics of static nested type stop doing that. snippet runs fine.

public class multiplenested {     static class nested {     }     public static void main(string[] args) {         (int = 0; < 100; i++) {             new nested();         }     } } 

see also


now, of course nested type can own instance control (e.g. private constructors, singleton pattern, etc) has nothing fact it's nested type. also, if nested type static enum, of course can't instantiate @ all.

but in general, yes, static nested type can instantiated multiple times.

note technically, static nested type not "inner" type.

jls 8.1.3 inner classes , enclosing instances

an inner class nested class not explicitly or implicitly declared static.

that is, according jls terminology, inner class 1 isn't static. if it's static, it's nested type.


so static mean?

static means nested type not need instance of enclosing type instantiated.

see also


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -