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

  • Home
  • SEARCH
  • 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 8411121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:21:39+00:00 2026-06-10T00:21:39+00:00

Enum.valueOf() cannot be hidden by another static method valueOf of a concrete Enum type,

  • 0

Enum.valueOf() cannot be hidden by another static method valueOf of a concrete Enum type, but since I am creating my objects with reflection from text files I need a generic way to invoke valueOf.

Currently my Enum has a static class fromString():

public enum Fruits {

   APPLE, ORANGE, ...;

    public static Fruit fromString(String fruit) {
        ...
    }
}

But how could I interface such a method that when I am dealing with an enum field type I invoke the appropriate method? The only thing I can think of is:

  • using a marker interface
  • implement this static method for every enum
  • invoke the static method via reflection

Is there another alternative which enforces this restriction?

  • 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-10T00:21:40+00:00Added an answer on June 10, 2026 at 12:21 am

    If I understand correctly, you’ll have a number of distinct enums that you want to integrate through the unique fromString method. What I have done is to make a separate class that accumulates all enum members into a single static final Map and the fromString method is implemented in terms of it.

    All enums implement a common interface in my case because I have a number of custom methods that I need to call irrespective of the exact enum in question.

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

Sidebar

Related Questions

How can I access static method of the enum if given enum is a
I need to re-implement the enum.valueof method of a few of my enumerations so
Namely I would like to write my own valueOf for enums, since this method
Assume I have a generic type P which is an Enum, that is <P
I have a custom toString method in my enum: enum TaxRate implements Serializable {
I'm trying to derive an enum value from a String, like: Level level =
I need to get a Java enum value from a string given Enum's Class
According to msdn Enums cannot have a base type of char. Why can enums
If I have the following enum type: typedef enum {Type1=0, Type2, Type3} EnumType; And
Enum is in the java.lang.Enum , and Object is in the java.lang.Object . So,

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.