From: Arne Vajhøj on
On 15-12-2009 17:02, Roedy Green wrote:
> On Sun, 13 Dec 2009 20:32:34 -0500, Arne Vajh�j<arne(a)vajhoej.dk>
> wrote, quoted or indirectly quoted someone who said :
>> I guess you could do that.
>>
>> But then what benefits would that static method provide
>> that a similar non-static method would not provide?
>
> same thing a normal static method does: single copy of variable
> common to all instances, persistence, ability to count instances.

But the static method can not be called from a static context,
so whatever it does could be achieved by making it non static.

And regarding counting instances, then look at what Mike Schilling
considers sensible.

Arne


From: Lew on
Mike Schilling wrote:
> Perhaps I wasn't clear, becasue what I'm thinking counts instances
> quite well, e.g.
>
> class Outer
> {
> class Inner
> {
> static int count;
>
> Inner()
> {
> count++;
> }
> }
> }
>
> "count" willl give the number of Inner.Outer instances ever created,

This is quite attainable without changing the rules, natch. While some seem
to prefer the syntax of the 'static' member being within the inner class,
there's no real disadvantage to the currently-legal idiom. We just have to
adapt our esthetic to The Way It Is in Java, and chalk it up as yet another
thing we'd have done better were it up to us, accepting that we can at least
achieve the functional equivalent if not through the means we imagine we'd
prefer. Oh, well.

> regardless of the value of the enclosing Inner instance. Though in
> fact what I've usually wanted a static method for is when Inner needs
> a cache, e.g.
>
> class Outer
> {
> class Inner
> {
> static Map<String, Schema>schemas = new HashMap<String,
> Schema>();
> private Schema schema;
>
> Inner(String namespace)
> {
> synchronized(schemas)
> {
> schema = schemas.get(namespace);
> if (schema == null)
> {
> schema = loadSchema(namespace);
> schemas.put(namespace, schema);
> }
> }
> }
> }
> }
>
> Again, I want to use the same cache regardless of the value of the
> enclosing instance.

Again, you can do that with currently-legal syntax, just not the exact way you
suggest. Oh, well.

--
Lew
From: Arne Vajhøj on
On 03-01-2010 01:36, Mike Schilling wrote:
> Arne Vajh�j wrote:
>> On 15-12-2009 17:02, Roedy Green wrote:
>>> On Sun, 13 Dec 2009 20:32:34 -0500, Arne Vajh�j<arne(a)vajhoej.dk>
>>> wrote, quoted or indirectly quoted someone who said :
>>>> I guess you could do that.
>>>>
>>>> But then what benefits would that static method provide
>>>> that a similar non-static method would not provide?
>>>
>>> same thing a normal static method does: single copy of variable
>>> common to all instances, persistence, ability to count instances.
>>
>> But the static method can not be called from a static context,
>> so whatever it does could be achieved by making it non static.
>>
>> And regarding counting instances, then look at what Mike Schilling
>> considers sensible.
>
> Perhaps I wasn't clear, becasue what I'm thinking counts instances
> quite well, e.g.
>
> class Outer
> {
> class Inner
> {
> static int count;
>
> Inner()
> {
> count++;
> }
> }
> }
>
> "count" willl give the number of Inner.Outer instances ever created,
> regardless of the value of the enclosing Inner instance.

OK. I misunderstood what you wanted then. That is sensible
and consistent.

Arne