• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Programming restrictictions

 
Peter Warde
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know you can't use a static variable, but can you use a static final variable ie a constant? What about static methods in beans?
 
Severin Stoeckli
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use static methods in a helper class there's no problem. If you use static methods in your bean class directly there could be a problem, depending on your container implementation. The countainer is allowed to subclass your bean and could miss to take in count that you could made a static class.

Remark: don't use static members in helper classes!!! (they have tha same effect as in your bean class).
 
Roger Yates
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using static *final* variables is ok (as long as it is not a final reference to a modifiable class instance!).
e.g. this would be ok:
static final int ONE = 1;
but this would not:
static final StringBuffer msg = new StringBuffer();

since you could still modify the data in the StringBuffer.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic