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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:08:30+00:00 2026-06-03T04:08:30+00:00

I am not a Java programmer. I read the documentation on final, and understand

  • 0

I am not a Java programmer. I read the documentation on “final”, and understand it to mean “a variable’s value may be set once and only once.”

I am translating some Java to C#. The code does not execute as expected. I tried to figure out why, and found some uses of final that don’t make sense.

Code snippet 1:

final int[] PRED = { 0, 0, 0 };
...
PRED[1] = 3;

Will PRED[1] be 0 or 3?

Code snippet 2:

final int[] PRED = new int[this.Nf];
for (int nComponent = 0; nComponent < this.Nf; nComponent++) {
    PRED[nComponent] = 0;
}
...
PRED[1] = 3;

Surely PRED[0] will remain as 0?

  • 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-03T04:08:31+00:00Added an answer on June 3, 2026 at 4:08 am

    I think you have a misunderstanding of the final keyword semantic when it is applied to arrays in Java.

    In both Java examples the arrays will remain unchanged, but their elements may be changed. All your assignments will be executed correctly, and the values stored in the array will get changed. However, if you try

    final int[] PRED = new int[this.Nf];
    // some other code
    PRED = new int[123]; // <<== Compile error
    

    you are going to see a compile error.

    When translating your code to C#, you may need to translate final either as sealed (when it is applied to a class), or as readonly (when it is applied to a member). The semantic of readonly arrays in C# and final arrays in Java are the same: your program cannot reassign the array, but it can freely modify its elements.

    Finally, there is a Java-specific case when final is used where you wouldn’t need it in C# at all: when you need to use a variable inside a method of an anonymous local class in Java, you must make that variable final. Since C# does not have anonymous local classes, you would need to translate that piece of code with something else, perhaps with anonymous delegates. Such delegates are not restricted to using readonly variables.

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

Sidebar

Related Questions

I want to read a value from textfied in Java but I am not
This is not homework. I am a beginner (novice) java programmer, trying to read
After hours of work (I'm not a java programmer) I've managed to pack and
I am not an experienced Java programmer and i'm trying to write some text
I'm not the worlds most experienced Java programmer, and I'm trying to create a
I'm not a Java programmer at all. I try to avoid it at all
I am not a Java programmer. I program R and C++. I have some
let me introduce. I'm an enthusiast programmer (not professional) with c, c++, java experience
I'm not a Java programmer and I'm not sure if what I'm doing is
So starting to learn C++. I am a pretty decent (not great) Java Programmer

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.