ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Donald <dona...@apache.org>
Subject Re: javac, depend, and interface constants
Date Mon, 23 Jul 2001 16:03:24 GMT
On Tue, 24 Jul 2001 01:04, Larry V. Streepy, Jr. wrote:
> After some digging, it appears that the compiler is removing the actual
> class member references and just embedding the constant directly into
> the generated class file.  This happens even with debug turned on and
> optimization turned off.  

yup - painful isn't it ;)

> Even declaring them as non-final seems to have no effect.

yer ? hmmm. What compiler are you using and did you make sure you did a full 
rebuild ?

> Does anyone have ideas on how to fix, prevent, work around this?

3 strategies I have used in the past include;

* grab constant from system property. ie
 public static final String MY_CONST = 
   System.getProperty("my.prop-str","const-value-here");
 public static final int MY_CONST = 
  Integer.getInteger("vars.MY_CONST", new Integer(2) ).intValue();

but that gets ugly fast.

* Instead of using primitive types or strings, use Objects. (They can't be 
inlined legally). ie Have a look at

http://cvs.apache.org/viewcvs/~checkout~/jakarta-avalon/src/java/org/apache/avalon/framework/Enum.java?rev=1.2&content-type=text/plain
http://cvs.apache.org/viewcvs/~checkout~/jakarta-avalon/src/java/org/apache/avalon/framework/ValuedEnum.java?rev=1.4&content-type=text/plain

* Have the users (or used) have dummy references to each other. ie I used to 
use this pattern all the time

final class FooPackage
{
  static final boolean DEBUG_MyClassInFooPackage = true;
  static final boolean TRACE_MyClassInFooPackage = true;
}

and then 

class MyClassInFooPackage
{
  public final static Class DEPS_HACK = FooPackage.class;
}

None of them are really good (well the second method is good for enums) but 
it was the only thing that I knew of that is easy to implement and force 
recompiles.

Cheers,

Pete

*-----------------------------------------------------*
| "Faced with the choice between changing one's mind, |
| and proving that there is no need to do so - almost |
| everyone gets busy on the proof."                   |
|              - John Kenneth Galbraith               |
*-----------------------------------------------------*

Mime
View raw message