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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:57:52+00:00 2026-06-12T08:57:52+00:00

A final object cannot be changed, but we can set its attributes: final MyClass

  • 0

A final object cannot be changed, but we can set its attributes:

final MyClass object = new MyClass();
object.setAttr("something");              //<-- OK
object = someOtherObject;                 //<-- NOT OK

Is it possible to do the same with a final Integer and change its int value?

I’m asking because I call a worker:

public SomeClass myFunction(final String val1, final Integer myInt) {

    session.doWork(new Work() {
    @Override
    public void execute(...) {
        //Use and change value of myInt here
        //Using it requires it to be declared final (same reference)
    }
}

And i need to set the value of myInt inside of it.

I can declare my int inside another class, and that would work. But I wonder if this is necessary.

  • 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-06-12T08:57:54+00:00Added an answer on June 12, 2026 at 8:57 am

    No : an Integer is immutable, just like for example String.

    But you can design your own class to embed an integer and use it instead of an Integer :

    public class MutableInteger {
        private int value;
        public MutableInteger(int value) {
            this.value = value;
        }
        public int getValue() {
            return value;
        }
        public void setValue(int value) {
            this.value = value;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

DZone refcard titled Core Java Concurrency states: Once set, final field values cannot be
The definition of immutability states that the state of an object (its data) cannot
If a String object is immutable (and thus obviously cannot change its length), why
Consider an object declared in a method: public void foo() { final Object obj
Is it true that the assigned final object field may still be null inside
I'm trying to make this code generic: public final Object unwrap(Class arg0) { throw
Is there a way to find out the final location of my animated object
I'm using Hibernate 4.0.1.Final and MySQL 5.1. My domain object contains a java.util.Calendar object
private final List<KeyListener> keyListeners= new CopyOnWriteArrayList<KeyListener>(); public void addKeyListener(KeyListener keyListener){ keyListeners.add(keyListener); } In the
Is it possible to have final transient fields that are set to any non-default

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.