Thursday, July 28, 2011

Re: [android-developers] Static Initializers - interdependencies

On 28 July 2011 15:51, RLScott <fixthatpiano@yahoo.com> wrote:
> What happens if I have two classes, each with some static variables,
> and some initializer in one class references a static variable in
> another class?
>
> the beginning of class A:
>
>  public static ByteBuffer audioInByteBuffer =
> ByteBuffer.allocateDirect(Main.bytesPerBlock);
>
> and in the beginning of class Main:
>
>  public static int samplesPerBlock=1024;
>
> Is it possible for the static initializers of class A to run before
> the static initializers of class Main, so that Main.bytesPerBlock is
> not defined at the time it is used in the initializer of
> audioInByteBuffer?

No.
The static initialisation of class A references class Main.
This means that initialisation of class A will cause class Main to
load, which in turn will run its initialisers.

--
Daniel Drozdzewski

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment