<p>I have two classes, and want to include a static instance of one class inside the other and access the static fields from the second class via the first.  </p>

<p>This is so I can have non-identical instances with the same name.  </p>

<pre><code>Class A 
{
    public static package1.Foo foo;
}

Class B 
{
    public static package2.Foo foo;
}


//package1
Foo 
{
    public final static int bar = 1;
}

// package2
Foo
{
    public final static int bar = 2;
}

// usage
assertEquals(A.foo.bar, 1);
assertEquals(B.foo.bar, 2);
</code></pre>

<p>This works, but I get a warning "The static field Foo.bar shoudl be accessed in a static way".
Can someone explain why this is and offer a "correct" implementation.</p>

<p>I realize I could access the static instances directly, but if you have a long package hierarchy, that gets ugly:</p>

<pre><code>assertEquals(net.FooCorp.divisions.A.package.Foo.bar, 1);
assertEquals(net.FooCorp.divisions.B.package.Foo.bar, 2);
</code></pre>

You should use:
```
```
Foo.bar
```
```
And not:
```
```
A.foo.bar
```
```
That's what the warning means.
The reason is that
```
bar
```
isn't a member of an
instance
of
```
Foo
```
.  Rather,
```
bar
```
is global, on the class
```
Foo
```
.  The compiler wants you to reference it globally rather than pretending it's a member of the instance.