Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

non static compile time constant .vs. static in tomcat

Thread view: 
ptg_abhishek@yahoo.com - 17 Nov 2005 10:17 GMT
I just ran findbugs and it came up with this warning - "This class
contains an instance final field that is initialized to a compile-time
static value. Consider making the field static".

What is the difference whether a set of classes use variables
initialized to a compile-time constant [string literals], or whether a
set of static variables is used [apart from the knowledge that the
static variables persist as long as the application is alive]? Could
the use of static variables in a web-application pose any problems when
handling concurrent requests [threading handled by the Server]?

regards.
-abhishek.
Chris Uppal - 17 Nov 2005 11:35 GMT
> I just ran findbugs and it came up with this warning - "This class
> contains an instance final field that is initialized to a compile-time
[quoted text clipped - 3 lines]
> initialized to a compile-time constant [string literals], or whether a
> set of static variables is used

None.  Any final field (static or instance) that is initialised to a String
constant will (this is required by the language definition) be inlined by the
compiler at the points where the are used.  The same thing applies to numeric
and boolean final fields.  It also applies if the final field is not initalised
to a constant, but to a compile-time constant-valued expression.

There is little point in using an actual instance field when the value is a
fixed constant, and it takes up a little space in each object (the field is
still there, it is just not actually /used/), so you may as well use a static
constant.  Makes the intent of the code clearer too (there may be exceptions to
that, but I can't think of a plausible one offhand).

   -- chris


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.