Actually, I was talking more along the lines of:

class Outer {
  static Category cat = Category.getInstance(Outer.class.getName());

  private static class Inner {
    static Category catInner = Category.getInstance(Inner.class);
    Inner() {catInner.debug("in Inner constructor");}
  }

  Outer() {cat.debug("in Outer constructor");}
}

Again, the lone disadvantage is that you don't get the implicit Outer.this.

-Jim Moore

-----Original Message-----
From: Kitching Simon [mailto:[EMAIL PROTECTED]]
Sent: Monday, January 29, 2001 4:15 AM
To: 'LOG4J Users Mailing List'
Subject: RE: Static vs. non-static categories and inner classes


How about this as an alternative?

Declare the static log category in the outer class, eg

class Outer
{
  static Category cat = Category.getInstance(Outer.class.getName());
  static Category catInner = Category.getInstance(something);

  private class Inner
  {
    Inner() {catInner.debug("in Inner constructor");}
  }

  Outer {cat.debug("in Outer constructor");}
}

I'm not sure how you can tidily pass a suitable string to the
catInner constructor representing the inner class' name. And
the *name* of the Category variable used from the Inner class
must be different from the normal convention (cat) you've adopted,
but on the positive side, the log object only gets constructed
once.

Regards,

Simon

> -----Original Message-----
> From: Rex Madden [SMTP:[EMAIL PROTECTED]]
> Sent: Saturday, January 27, 2001 11:32 PM
> To:   LOG4J Users Mailing List
> Subject:      RE: Static vs. non-static categories and inner classes
> 
> Thanks Jim!  So it sounds like the performance and memory penalties are
> relatively small, unless those inner classes are created over and over
> again.  That's what I was hoping to hear...I just wanted to make sure
> there weren't any weird side effects.
>  
> Thanks again,
> Rex
>  
> -----Original Message-----
> From: Jim Moore [mailto:[EMAIL PROTECTED]]
> Sent: Saturday, January 27, 2001 5:16 PM
> To: 'LOG4J Users Mailing List'
> Subject: RE: Static vs. non-static categories and inner classes
>  
> If you use a "static inner class" (aka "top-level member class") then you
> can have static members in them.  They have all the capabilities of other
> top-level classes and then some.
>  
> If, however, you want the real advantage of an "inner class" (because you
> want to implicit OuterClass.this member) then the disadvantage of the
> non-static Category declaration in that class is a very small performance
> and memory penalty.  The performance penalty comes from having to look up
> the Category every time a new instance of the inner class is created.  The
> memory penalty is that each instance has another Reference associated with
> it.  (Since there's a hash guaranteeing that there's only one instance of
> a Category of a particular name, there's no performance or memory cost
> involved in creating new Categories for each inner class instance.)
>  
> -Jim Moore

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to