For Programmers: Free Programming Magazines  


Home > Archive > Java Help > March 2004 > Conventions for referring to a static (class) variable within the class its declared









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Conventions for referring to a static (class) variable within the class its declared
Inertia_sublimation

2004-03-27, 12:30 am

Hello all :)

I apologize in advance if this question seems overly newbie-ish, Im
wondering if there are any guidelines on how to use public static final
class variables (read: constants), that are decalred in the same class.

I know you use this format for when the constants are outside of the class:

import java.awt.Color;

public class MyClass extends Color{
private color myColor = Color.green; // Use Color.green, instead of just
gree
}

But what aboutconstants declared within the class?

Ex:

public class Example {
public static final int CONSTANT;

static {
CONSTANT = 5; // Is is better to use Example.CONSTANT here instead?
}
public Example() {
aMethod(CONSTANT); // Is it better to use Example.CONSTANT here
instead?
}
private void aMethod(int a) {
// Do stuff...
}
}
Thanks in advance! :)


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com