File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes compiling packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "compiling packages" Watch "compiling packages" New topic
Author

compiling packages

Peter Straw
Ranch Hand

Joined: Jan 08, 2002
Posts: 79
I have some final static variables in class A in package A, that are imported and referenced by class B in package B. If I change the values of these variables in class A and then recompile class A, do I also have to recompile class B or will it reference the new values of these variables at runtime?
Many thanks
[ January 07, 2003: Message edited by: Peter Straw ]
[ January 07, 2003: Message edited by: Peter Straw ]
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
Yes, you must recompile B. For optimization purposes, static final field values are inserted into the class bytecode when the class is compiled.
I like to think of them as being "hard-coded" into the bytecode during compilation, so you have to recompile in order to "hard-code" a different value.


Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
This is an issue with Binary Compatibility. Technically NO you do not have to recompile the B classes unless, of course, that you really WANT the to pick up the new value .
From the Java Language Specification
13.4.8 final Fields and Constants
If a field is a compile-time constant, then deleting the keyword final or changing its value will not break compatibility with pre-existing binaries by causing them not to run, but they will not see any new value for the constant unless they are recompiled.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Peter Straw
Ranch Hand

Joined: Jan 08, 2002
Posts: 79
Thanks a lot Blake and Cindy.
I DO want the new values to be picked up, so is there a way of storing and referencing these variables without having to re-compile the other package(s). Perhaps they should just be private member variables with get/set methods?
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
Originally posted by Peter Straw:
Perhaps they should just be private member variables with get/set methods?

Hmmm... do those values change often? If so then that's a different story, I'd recommend parameterizing them somehow (e.g. props file) and making them private members with get/set methods as you said.
Peter Straw
Ranch Hand

Joined: Jan 08, 2002
Posts: 79
No, the values don't change once the application has been installed. I'm not familiar with a Props file, perhaps that is the best solution though. I'll look into this, thanks.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
I think that he means that you can use a Properties file where the value of the property is read from a file (usually at start up).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: compiling packages