All Questions
10
questions
27
votes
3
answers
949
views
Why is the data array in java.util.ArrayList package-private?
In the java.util.ArrayList class, the object array for the list's elements is defined as package-private:
transient Object[] elementData; // non-private to simplify nested class access
The comment ...
1
vote
1
answer
4k
views
Using an inner class to create a private record for the outer class in java / inner methods visibility
I have to implement an interface called Graph<E> in Java.
Let's say MyGraph<E extends Comparable<E>> is the class I'm writing to implement Graph.
I would like to create an inner ...
-1
votes
1
answer
67
views
Choosing a descriptive visibility for members of a private inner class
In my data structures class, we are implementing the Nodes of a red/black tree using a private inner class. This kind of Node is unique to red/black trees, so the inner class's visibility is private. ...
52
votes
3
answers
6k
views
Why can nested child classes access private members of their parent class, but grandchildren cannot?
Probably similar to the question, Why can outer Java classes access inner class private members? or Access to superclass private fields using the super keyword in a subclass .
But there are some ...
-1
votes
1
answer
33
views
Interface visibility restriction, but runs fine
When designing a fluid API, sometimes I want to use Interface return types so that the caller can easily follow the available methods or gets compiler errors if he does not (the Step Builder pattern ...
0
votes
2
answers
188
views
Visibility of a private inner class of a public class
While this is obviously a RTFM case, somehow I failed to find a concise source explaining it all.
public class Outer {
private class Inner {
}
}
Private class Inner is an inner class of a ...
4
votes
6
answers
3k
views
How to access fields declared inside anonymous object?
Java lets you declare new fields inside anonymous classes, but I can't figure out how to access them from outside, even setting them to public doesn't let me.
class A {
public static void main(...
11
votes
2
answers
2k
views
Accessing private inner class in the same package
I have two compilation units:
public class OuterClass{
private static class InnerClass{
public String test(){
return "testing123";
}
}
public static void ...
8
votes
1
answer
1k
views
Static nested class visibility issue with Scala / Java interop
Suppose I have the following Java file in a library:
package test;
public abstract class AbstractFoo {
protected static class FooHelper {
public FooHelper() {}
}
}
I would like to extend ...
2
votes
2
answers
462
views
Why my inner class DO see a NON static variable?
Earlier I had a problem when an inner anonymous class did not see a field of the "outer" class. I needed to make a final variable to make it visible to the inner class. Now I have an opposite ...