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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:32:52+00:00 2026-06-06T14:32:52+00:00

I have enumeration in JAVA code ERequestTypes my enumeration contains more then 20 elements,

  • 0

I have enumeration in JAVA code ERequestTypes my enumeration contains more then 20 elements, every element is a name of a function in my JAVA code. Now I want do following thing instead of writing switch(ERequestTypes) case and in the cases calling function in this way:

switch(ERequestTypes a) {
    case ERequestTypes.Initialize:
        Initialize();
    case ERequestTypes.Uninitialize:
        Uninitialize();
}

I want to do it with one line. All the functions in the enum have same argument and return same int value. How I can do that ? may be keep pointers of functions in enum like in C++ or something else. Please help !

class CRequestValue {
    /**
     * Constructor.
     * 
     * @param aName - Name of the request.
     * @param aCode - Code of the request.
     */
    public CRequestValue(String aName, int aCode) {
        this.mName = aName;
        this.mCode = aCode;
    }

    private String mName;
    private int    mCode;

    public String GetName() {
        return this.mName;
    }

    public int GetCode() {
        return this.mCode;
    }

} /* class CRequestValue **/

enum ERequestTypes
{
    Initialize(new CRequestValue("Initialize", 0)),
    Uninitialize(new CRequestValue("Uninitialize", 1)),
    GetDeviceInfoList(new CRequestValue("GetDeviceInfoList", 2)),
    GetDeviceInfo(new CRequestValue("GetDeviceInfo", 3));

    private CRequestValue mRequestValue;

    private ERequestTypes(CRequestValue aRequestValue) {
        this.mRequestValue = aRequestValue;
    }

    public String GetName() {
        return this.mRequestValue.GetName();
    }

    public int GetCode() {
        return this.mRequestValue.GetCode();
    }

} /* enum ERequestTypes **/
  • 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-06T14:32:54+00:00Added an answer on June 6, 2026 at 2:32 pm

    You’re looking for reflection.

    ErequestTypes a = <init>;
    Object o = Class.forName(<your class name>).getMethod(a.getName(), <argtype>.class).invoke(<instance of your class, or null if static method>, <arg>);
    

    Note that the Class.forName is not required if you already know what class the methods are in.

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

Sidebar

Related Questions

Here is the Java code which I want to translate to C#: public Enumeration
I have the following implicit conversion for java.util.Enumerations implicit def enumerationIterator[A](e : Enumeration[A]) :
I was reading Enumerations in Java, and every example I have come across uses
i have code use googleseach API I want to use Thread to improve speed
OK I'm a beginner and I have to fix this java expression language code
I have a class that implements the Enumeration<T> interface, but Java's foreach loop requires
I have some old code (pre Java 1.5) that uses classes to implement type
I have some Java code and I would like to translate it to C#.
I have a custom EL function defined as follows: <function> ... <function-signature> java.lang.String getAsText(com.test.Outerclass.InnerEnum)
I have this enumeration: public enum Translation { English=1, Russian, French, German } I

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.