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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:12:29+00:00 2026-05-22T23:12:29+00:00

My question is close to this one but not quite the same. I have

  • 0

My question is close to this one but not quite the same.

I have an inherited (as in, I can’t/won’t change it) array of parameters in my class like so:

public double[] params;

The class utilises these parameters in complex ways, so I would prefer to have human-readable names for each element in the array. In C, you would do something like this

#define MY_READABLE_PARAMETER params[0]

I am also aware that in Java I could create a bunch of constants or an enumerator with attributes. Then, to access a parameter I’d have to type something like this:

params[MY_READABLE_PARAMETER]

This is acceptable but I would really like to omit the array name altogether. Is it possible?

  • 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-22T23:12:29+00:00Added an answer on May 22, 2026 at 11:12 pm

    If you have an array of doubles and each array element in a specific position has a definite meaning you should create a class instead.

    public class MyParamBlob extends ParentParamBlob
    {
        private double myReadableParameter;
        private double anotherParameter;
        private double yetOneMore;
    
        // getters and setters as appropriate
    }
    

    If you need to deal with an existing double[] from “outside” you could have a constructor and/or a method that takes an array as a parameter.

    public class MyParamBlob
    {
        ...
        public MyParamBlob(double[] values)
        {
            setAll(values);
        }
        // getters and setters as appropriate
        ...
        public void setAll(double[] values)
        {
            myReadableParameter = values[0];
            anotherParameter = values[1];
            // etc.
        }
    }
    

    Edit – to explain my comment

    If the original parent class that this is a subclass of (the reason the double[] exists in the first place) has a getter for the array, that could be overridden in this class, building and returning the array when requested — e.g.

    public double[] getParams()
    {
        double[] params = new double[4];
        params[0] = myReadableParameter;
        params[1] = anotherParameter;
        // etc.
    }
    

    If the array is directly accessible from an instance of the parent class, without a getter, e.g. myArray = parentInstance.params or double d2 = parentInstance.params[2] then (1) that’s a bad design and (2) callers could change the array values out from under you parentInstance.params[1] = 0.0;

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

Sidebar

Related Questions

This question comes close to what I need, but my scenario is slightly different.
Closed as exact duplicate of this question . I have an array/list of elements.
I have searched but cant find this question anywhere. My wife and I are
Although this question and this question are close to what I'm asking, I believe
Closed as exact duplicate of this question . But reopened, as the other Singleton
(I am sorry, I wanted to ask this question on meta first, but it
This question comes from my experience with the following question: https://stackoverflow.com/questions/492748/new-responses-icon-on-so-crashes-ie7-closed In that question,
UPDATE: See my answer to this question first. This appears to be a bug.
This is something now more of curiosity than actual purpose. If you have a
(I'm using the pyprocessing module in this example, but replacing processing with multiprocessing should

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.