Group: comp.lang.java.programmer
From: ram@zedat.fu-berlin.de (Stefan Ram)
Date: Sunday, April 13, 2008 8:55 PM
Subject: Re: Problem with hiding the implementation

ram@zedat.fu-berlin.de (Stefan Ram) writes:
>public static void acceptAGeneratorFromA( final AGenerator aGenerator )
>{ Z.aGenerator = aGenerator; }}

It is still possible that some »end user« calls this method
and foists an illegal reference on it.
The following declaration makes this method more secure:

public static void acceptAGeneratorFromA( final AGenerator aGenerator )
{ if( aGenerator == null )throw new java.lang.NullPointerException();
if( Main.aGenerator == null )Main.aGenerator = aGenerator; }

Usually, immediatly upon initialization of its class the field
»aGenerator« will be set by this method to a non-zero value.
Any attempt to modify it later will be difficult for a third party,
because of the final if-statement.