So, inside a bigger class, there is a local private class that i need to use for a method later on, but i don't know how to access it...
The private class, which i cannot change because it's part of the exercise, looks like this:
private class Counter
{
String element;
int frequency;
Counter (String element)
{
this.element = element;
frequency = 0;
}
String element() {
return this.element;
}
}
And the method I need to implement, which should add the Id with its frequency to the frequency list lf, looks like this:
private void update (String id, IList<Counter> lf)
{
}
I´m trying to use the add method from the IList, but i don't know how to use a type Counter, since it is a privae class and I can't access it.
Assuming the following starting class (NO, it is not the solution):
To access
Counter
inside ofupdate
, we can just write:Note:
Counter
is not a local class, but an inner class (I assumed one, since local classes cannot be declaredprivate
).The access to private inner classes and even to private members of such classes from within the same containing class, is allowed by JLS 6.6.1: