nested-class

Why instantiation of static nested class object is allowed?

非 Y 不嫁゛ 提交于 2019-11-28 06:52:19
I have started learning Java language for Android Application developement. As per my understanding based on static class, we cannot instantiate object of static class. But why instantiation of static nested class object is allowed in following situaltion? class EnclosingClass { //... class static StaticInnerClass { //... } } Why we can create object of inner class if it is marked as static? EnclosingClass.StaticInnerClass s = new EnclosingClass.StaticInnerClass() As per my understanding based on static class, we cannot instantiate object of static class. Your understanding of the meaning of

Why can't a class extend its own nested class in C#?

牧云@^-^@ 提交于 2019-11-28 06:16:52
For example: public class A : A.B { public class B { } } Which generates this error from the compiler: Circular base class dependency involving 'A' and 'A.B' I always figured a nested class behaved just like a regular class except with special rules concerning accessing the outer class's private members, but I guess there's some implicit inheritance occurring between the two classes? There's no implicit inheritance involved as far as I can tell. I would have expected this to be okay - although I can imagine weirdness if A and B were generic. It's specified in section 10.1.4 of the spec: When a

Access base class attribute in derived class - in “class scope”

独自空忆成欢 提交于 2019-11-28 05:08:35
问题 class Outer(object): class InnerBase(object): _var = {'foo', 'bar'} class Derived(InnerBase): _var = _var | {'baz'} # NameError: name '_var' is not defined _var = InnerBase._var | {'baz'} # name 'InnerBase' is not defined _var = Outer.InnerBase._var | {'baz'} # free variable 'Outer' # referenced before assignment in enclosing scope Moving _var in Outer does not help - moving it in module scope would work but defeats the purpose of having classes. So how to go about that ? EDIT: coming from

Inner class in interface vs in class

别说谁变了你拦得住时间么 提交于 2019-11-28 04:22:42
What is the difference between these two innerclass declarations? Also comment on advantages/disadvantages? case A: class within a class. public class Levels { static public class Items { public String value; public String path; public String getValue() { return value;} } } and case B: class within interface. public interface Levels{ public class Items { public String value; public String path; public String getValue() { return value;} } } Made correction: to placement of getvalue method. further info: I am able to instantiate Items class in both cases A and B in another class that does not

Private nested Java class in UML diagram

吃可爱长大的小学妹 提交于 2019-11-28 02:42:56
问题 I have a question regarding UML. I have a class which simply contains an inner class with the private access modifier - cannot be accessed from anywhere else... Normally in order to present an inner class relation I can use a (+) relation like here ( InnerOddIterator ): (taken from http://www.uml-diagrams.org/nested-classifier.html) I have not found anywhere any information about how can clearly emphasize that this class is private. Do you know if such a method exist at all? If yes I'll be

Nested class is not defined in itself

不羁岁月 提交于 2019-11-28 01:39:35
问题 The following code successfully prints OK : class B(object): def __init__(self): super(B, self).__init__() print 'OK' class A(object): def __init__(self): self.B() B = B A() but the following which should work just as same as above one raises NameError: global name 'B' is not defined class A(object): def __init__(self): self.B() class B(object): def __init__(self): super(B, self).__init__() print 'OK' A() why? 回答1: B is available in the scope of A class - use A.B : class A(object): def __init

Can a nested C++ class inherit its enclosing class?

江枫思渺然 提交于 2019-11-27 23:05:09
问题 I’m trying to do the following: class Animal { class Bear : public Animal { // … }; class Giraffe : public Animal { // … }; }; … but my compiler appears to choke on this. Is this legal C++, and if not, is there a better way to accomplish the same thing? Essentially, I want to create a cleaner class naming scheme. (I don’t want to derive Animal and the inner classes from a common base class) 回答1: You can do what you want, but you have to delay the definition of the nested classes. class Animal

GC performance hit for inner class vs. static nested class

十年热恋 提交于 2019-11-27 14:32:06
问题 I just came across a weird effect and while tracking it down, I noticed that there seems to be a substantial performance difference for collecting inner vs. static nested classes. Consider this code fragment: public class Test { private class Pointer { long data; Pointer next; } private Pointer first; public static void main(String[] args) { Test t = null; for (int i = 0; i < 500; i++) { t = new Test(); for (int j = 0; j < 1000000; j++) { Pointer p = t.new Pointer(); p.data = i*j; p.next = t

c# Public Nested Classes or Better Option?

橙三吉。 提交于 2019-11-27 13:40:51
I have a control circuit which has multiple settings and may have any number of sensors attached to it (each with it's own set of settings). These sensors may only be used with the control circuit. I thought of using nested classes like so: public class ControlCircuitLib { // Fields. private Settings controllerSettings; private List<Sensor> attachedSensors; // Properties. public Settings ControllerSettings { get { return this.controllerSettings; } } public List<Sensor> AttachedSensors { get { return this.attachedSensors; } } // Constructors, methods, etc. ... // Nested classes. public class

Eclipse warning about synthetic accessor for private static nested classes in Java?

夙愿已清 提交于 2019-11-27 13:01:19
My coworker suggested making several of the Eclipse code-formatting and warning settings to be more rigorous. The majority of these changes make sense, but I get this one weird warning in Java. Here's some test code to reproduce the "problem": package com.example.bugs; public class WeirdInnerClassJavaWarning { private static class InnerClass { public void doSomething() {} } final private InnerClass anInstance; { this.anInstance = new InnerClass(); // !!! this.anInstance.doSomething(); } } // using "this.anInstance" instead of "anInstance" prevents another warning, // Unqualified access to the