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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:38:38+00:00 2026-05-24T21:38:38+00:00

Consider a third-party class like class A { private int value; public int getValue()

  • 0

Consider a third-party class like

class A {
    private int value;
    public int getValue() {
        return value;
    }
    public void setValue(int value) {
        this.value = value;
    }
}

which I make immutable like

final class ImmutableA extends A {
    public ImmutableA(int value) {
        super.setValue(value);
    }
    public void setValue(int value) {
        throw new UnsupportedOperationException();
    }
}

The visibility guarantee for final fields doesn’t apply here. My question is if other threads are guaranteed to see the correct state of ImmutableA.

If not, is there a solution? Using delegation is not an option since I need ImmutableA to be an 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-24T21:38:39+00:00Added an answer on May 24, 2026 at 9:38 pm

    You could use synchronized, though this may slow down the getter:

    final class ImmutableA extends A 
    {
        public ImmutableA(int value) {
            synchronized (this) {
                super.setValue(value);
            }
        }
    
        public void setValue(int value) {
            throw new UnsupportedOperationException();
        }
    
        public synchronized int getValue() {
            return super.getValue();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider: class B { public: int i = 4; } class A { public:
Consider this problem: I have a program which should fetch (let's say) 100 records
Consider these classes. class Base { ... }; class Derived : public Base {
Consider the following code. public interface IFoo { } public class Bar { public
I'm writing a wrapper class for a third-party web service(SOAP) api. I want to
Consider I have 2 classes: public class ComplicatedParent { // Lots of data }
Consider these two function definitions: void foo() { } void foo(void) { } Is
Consider the Oracle emp table. I'd like to get the employees with the top
I'm using a third party storage system that only returns me stdClass objects no
Consider this situation: There's a critical VB6 desktop application running on a production box.

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.