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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:26:18+00:00 2026-06-16T03:26:18+00:00

Why won’t declaring an array final make it immutable in Java? Doesn’t declaring something

  • 0

Why won’t declaring an array final make it immutable in Java? Doesn’t declaring something final mean it can’t be changed?

From question related to immutable array it’s clear that declaring an array final doesn’t make it unchangeable.

The following is possible.

final int[] array = new int[] {0, 1, 2, 3};
array[0] = 42;

My question is: What is the function of declaring final here then?

  • 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-16T03:26:19+00:00Added an answer on June 16, 2026 at 3:26 am

    final is only about the reference that is marked by it; there is no such thing as an immutable array in Java. When you say

    private final int[] xs = new int[20];
    

    you won’t be allowed to say

    xs = new int[10];
    

    later on. That’s all what final is about. More generally, ensuring that an object is immutable is often hard work and full of a range of subtleties. The language itself doesn’t give much to this end out of the box.

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

Sidebar

Related Questions

Why won't this code draw parabola? It is as simple as it can be
Won't the union in this question cause UB when used as this: union Data
Why won't Environment.GetEnvironmentVariable(variableName) get a variable's value if the call is made from within
Why won't this work in Oracle? Is there a way to make this work?
I sure hope this won't be an already answered question or a stupid one.
From reasons I won't get into, all our unit tests are using the VSTS
This won't be a long or complex question. I'm just wondering if there is
Vim won't convert fileformat if it sees inconsistent line endings. How can I find
Why won't this work? $stmt = $pdo->prepare(SELECT :columns FROM table); $stmt->bindParam(':columns', implode(', ', $columns),
C# won't let me cast a type T to a type I can prove

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.