classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: redundant field initializers


From: Mark Wielaard
Subject: Re: redundant field initializers
Date: Mon, 20 Sep 2004 22:02:22 +0200

Hi,

On Mon, 2004-09-20 at 11:43, Jeroen Frijters wrote:
> Do we have a coding style guideline about redundant field initializers?
> I have a patch that removes a couple of these for static fields that
> needlessly result in a static initializer method.
> 
> For example in javax.naming.spi.NamingManager:
> 
> -  private static InitialContextFactoryBuilder icfb = null;
> +  private static InitialContextFactoryBuilder icfb;
>  
>    // Package private so DirectoryManager can access it.
> -  static ObjectFactoryBuilder ofb = null;
> +  static ObjectFactoryBuilder ofb;
>
> Making this change removes the need for the compiler to create a static
> initializer.

Why would a compiler emit extra initialization code for default values
for fields? Not that I object to removing them, but it looks like the
compiler emits unnecessary code in this case.

> Does everyone agree that this is a good idea? If so, how far should we
> take this? How about this change:
> 
> -  private static int dispatchThreadNum = 1;
> +  private static int dispatchThreadNum;
>  
>    private EventQueue queue;
>  
>    EventDispatchThread(EventQueue queue)
>    {
>      super();
> -    setName("AWT-EventQueue-" + dispatchThreadNum++);
> +    setName("AWT-EventQueue-" + ++dispatchThreadNum);
>      this.queue = queue;
>      setPriority(NORM_PRIORITY + 1);
>      start();

This change seems more logical than the change above since you are
removing an initialization of a field with a non-default value (if not
initialized).

Cheers,

mark

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]