Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6069129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:47:20+00:00 2026-05-23T09:47:20+00:00

I have a Java project that involves the class GUIConstants –various public static final

  • 0

I have a Java project that involves the class GUIConstants–various public static final parameters used for laying out the GUI, since different components sometimes have to be the same size or color or whatever.

I’m currently in a stage of doing a visual redesign, which involves changing a few of those constants. However, ant is making this difficult. I’ll change a parameter and recompile, but the old value is still used. If I add some trivial modification to one of the files that uses it and recompile, the correct value will be used. But it’s annoying and error-prone to have to track down all the files and modify them. Surely there’s a way to force ant to recompile unchanged files…I just couldn’t find it in the man page.

Sidenote: My hypothesis is that when a class that uses a final variable is compiled, Java instead uses the value itself, not a reference to whatever the variable is pointing at (in a similar fashion to the way using #DEFINE for constants works in C). So even when the variable points to something else, the original value is baked into the .class file. Is this true? (It doesn’t affect my problem, I’m just curious.)

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:47:21+00:00Added an answer on May 23, 2026 at 9:47 am

    Your hypothesis is almost right. It’s not simply final variables though, but so called "constant variables":

    We call a variable, of primitive type or type String, that is final and initialized with a compile-time constant expression (§15.28) a constant variable. Whether a variable is a constant variable or not may have implications with respect to class initialization (§12.4.1), binary compatibility (§13.1, §13.4.9) and definite assignment (§16).

    Then in the section on binary compatibility (§13.1):

    References to fields that are constant variables (§4.12.4) are resolved at compile time to the constant value that is denoted. No reference to such a constant field should be present in the code in a binary file (except in the class or interface containing the constant field, which will have code to initialize it)

    and (§13.4.9) (my emphasis):

    If a field is a constant variable (§4.12.4), 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 usage of the field unless they are recompiled.

    In a previous job, we made use of this to have a sort of conditional compilation system, so that we could produce production binaries with all the debug statements stripped out.

    When you combine this with the way the javac task determines what classes to recompile you get the behaviour you are seeing:

    Only Java files that have no corresponding .class file or where the class file is older than the .java file will be compiled.

    Note: Apache Ant uses only the names of the source and class files to find the classes that need a rebuild. It will not scan the source and therefore will have no knowledge about nested classes, classes that are named different from the source file, and so on. See the <depend> task for dependency checking based on other than just existence/modification times.

    The simplest way to fix this would be to do a clean full compile every time, with something like ant clean compile (assuming you have a clean target that removes all your class files). This might be too slow though.

    I was also going to suggest that you look at the depend task, as suggested in the docs for the javac task, but looking at the docs for it (I haven’t actually used it myself) it seems that it won’t help (see the section titled "Limitations"):

    The most obvious example of these limitations is that the task can’t tell which classes to recompile when a constant primitive data type exported by other classes is changed.

    One possible workaround, if you find doing a clean compile every time too slow, would be to make the values in your GUIConstants class not be constants, at least whilst you make your changes. You could make the values non-final by commenting out all the final keywords, then the other classes should see your changes. When you are happy with the new values, put the finals back in and recompile (and test that everything is still working properly of course).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a software-project written in java you often have resources, that are part of
Java Newbie here. I have a JFrame that I added to my netbeans project,
I have been working on a Java project for a class for a while
I have a java project in Eclipse that I am trying to run/debug. When
I have a rather complex project here that involves a lot of calculations. Now
I have Java project that uses a JAR from another Eclipse project (open source
I have a Java project that uses this driver for serial communication. The driver
I have a Java project that utilizes Jython to interface with a Python module.
I have a have a java project that serializes some objects and ints to
I have a Java project that builds using Apache Ant to a website. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.