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

The Archive Base Latest Questions

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

I have a large enum declared in my class public enum CarMaker{ Honda, Toyota,

  • 0

I have a large enum declared in my class

public enum CarMaker{
        Honda,
        Toyota,
        Sony,
        ...;

        public CarMaker at(int index){ //a method to retrieve enum by index
                CarMaker[] retval = this.values();
                return retval[index];
        }
        public final SomeObj val; //a value associated with each enum
            //.. more custom functions if needed
    }

since only one instance of each CarMaker is needed, is it a bad practice if I want to use this enum as a storage (like an array but instead access each element using indices, I could use more intuitive names. Also I can have custom functions for each element)

CarMaker A = CarMaker.Honda;
CarMaker B = CarMaker.at(1); 
//Error above b/c 'at' is not a static member, can I make at a static member?

A.val = 5; 
B.val = 6; 
//Here I want A to be share data with B since both are "Honda"
//but it doesn't seem to do that yet
 System.out.println(A)
 System.out.println(B)

//Expected output:
//A: 6
//B: 6

Right now A and B seem to create their own instance of “Honda”, but I want them to be shared. 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-06-03T23:00:01+00:00Added an answer on June 3, 2026 at 11:00 pm

    Use your enum but via composition: Create an enum of brand names, but then build your objects that need a name to hold a field of the enum.

    Example

    public enum CarMaker {
       Honda,
       Toyota,
       Sony,
       Olympus,
       Facebook,
       Google,
       ...
    }
    
    public class Car {
       CarMaker carMaker;
       //... etc....
    
       Car(CarMaker carMaker) {
          this.carMaker = carMaker;
          // ... more code
       }
    
       //....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have enum like this public enum Sizes { Normal(232), Large(455); private final int
I have a synchronized Hashtable with int as the key, and a custom class
I have a class that uses the __set magic method. One of the properties
I have a method that needs to retrieve a type of size so for
I have a class extracting strings from a large file (100,000) lines and wanted
In the program I am creating, I have a large amount of enums enum
I have large images displayed in a grouped tableview. I would like the images
I have large database table, approximately 5GB, now I wan to getCurrentSnapshot of Database
I have large video files (~100GB) that are local on my machine. I have
I have large set of flow charts and workflow diagrams. I want to draw

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.