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 6217277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:23:55+00:00 2026-05-24T07:23:55+00:00

public class TestData { public static final String DATA = A; // I change

  • 0
public class TestData {
   public static final String DATA = "A"; // I change this to read DATA = "B"
}

public class MyTest extends UnitTest {
   private MyClass myClass;

   public void setUp() {
      myClass = new MyClass(TestData.DATA); // After change, DATA has value "B"
   }
}

public class MyClass {
   private String myVar;

   public MyClass(String myVar) { // After change, myVar still has value "A"
      this.myVar = myVar;   
   }
}
  1. Change TestData.DATA to B by editing the source code in Eclipse
  2. Restart server
  3. Run MyTest
  4. MyClass still receives A when referencing TestData.DATA
  5. ???

Things I tried: restart server, eclipsify project, clean project, restart eclipse, restart computer, refresh every file manually. I found this to work:

String data = TestData.DATA;
myClass = new MyClass(data);

Why can’t I pass DATA directly to MyClass constructor?

I’ve got no error messages, when I break at setUp, DATA has the value “B” since I’ve changed it, but when I step into MyClass myVar has the value “A”

  • 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-24T07:23:56+00:00Added an answer on May 24, 2026 at 7:23 am

    You can’t change a final variable. That’s what makes it final. But there is nothing wrong with passing the final variable to a function. In fact, the sample code that you posted runs just fine.

    In your list of steps, you said ‘change DATA to “B”‘ though your code doesn’t show this step. But that’s fine, since that step wouldn’t compile.

    If you need to alter a final variable before passing it to a function, you need to make a local copy and change that copy instead.

    Update: Now that the question has been clarified, here are some more thoughts:

    It sounds like something isn’t being recompiled properly. Perhaps you are running from an old version of the classes (i.e. you need to copy it somewhere)?

    Also, you should know that although you may change the TestData class, because DATA is declared static final, Java may have inlined that constant into the MyTest class (since it is guaranteed to never change) so you need to make sure that MyTest is also recompiled.

    If you want to verify that you are using the latest version of a class, put some very “loud” code in a place where you know it should execute. For example, a System.out.println or even throw a RuntimeException (sure, your program will fail, but if it doesn’t fail then you know that something isn’t being recompiled properly which will help you diagnose what is wrong).

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

Sidebar

Related Questions

public class Test { public static void main(String[] args) { } } class Outer
public class doublePrecision { public static void main(String[] args) { double total = 0;
public class WrapperTest { public static void main(String[] args) { Integer i = 100;
public class EventsType { public event EventHandler> NewEvent; public void SmthHappened(string data) { MyEventArgs<Object>
public class Greeter extends MovieClip { public function Greeter() { addEventListener(Event.ADDED_TO_STAGE, go); } private
public class Empty { public static void main( String[] args ) { TreeSet<Class> classes
public class PeopleCollection : IEnumerable { private Dictionary<string, Person> listPeople = new Dictionary<string, Person>();
public class Main { public static void main(String[] args){ XClass x = new XClass();
public class Person { private int _Id; public int Id{get{return value;} set{_Id=value;}} private string
public class ArrayTest{ public static void main(String[] args){ String[] list = {key1, key2, key3};

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.