All Questions
Tagged with nested-class or inner-classes
2,927 questions
-5 votes
0 answers
79 views
Reaching constructors in a java static context [closed]
We cannot instantiate an inner class within a static context of the outer class, but when we declare this inner class as package- private. we are able to access its constructor. But how ? what is the ...
Advice
2 votes
4 replies
247 views
Can function-local class be defined in the global scope?
Any C++ class can be first forward declared, and defined only later in the program. Are function-local classes an exception from this rule? Please consider a simplified program: auto f() { struct ...
0 votes
1 answer
77 views
Can nested classes or even anonymous classes extend a class or implement a interface? [closed]
Can nested classes or anonymous classes extend a class or implement an interface in Java? If so, are there any limitations or things I should be aware of? I'm not very familiar with nested classes, ...
0 votes
2 answers
58 views
How can I override super.nested test class?
Say, I have an abstract superclass and an abstract test class for testing subclasses. abstract class Superclass { } @RequiredArgsConstructor abstract class SuperclassTest<T extends Superclass> {...
2 votes
1 answer
45 views
Type mismatch when using generics with abstract nested classes
I find an "Argument type mismatch" error in multiply function and don't know how to fix it. The code is: abstract class Semigroup<T1> { abstract val one: SemigroupElement<T1> ...
1 vote
0 answers
69 views
How to implement a class of a specialized template class
suppose I have a template class template<typename T> struct Foo { struct Bar; }; specializing Foo<int>::Bar template<> struct Foo<int>::Bar { struct Private; // I ...
-1 votes
2 answers
89 views
Why does Java allow static methods within an Inner class [duplicate]
Java shouldn't allow static methods within an inner class and yet this code compiles and runs. How is this possible? class Test{ static int j=20; public void m1() { class Inner{ ...
0 votes
2 answers
180 views
Why does the constructor of a non-private inner member class need a variable representing the immediately enclosing instance of this class?
I am very curious about this question. The Java Language Specification has told me part of the reason: In a class instance creation expression for a non-private inner member class, §15.9.2 specifies ...