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

The Archive Base Latest Questions

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

I have a number of enums that each have the same fields and the

  • 0

I have a number of enums that each have the same fields and the same methods.

public enum AddressSubType {
    DOM("dom"), INTL("intl"), POSTAL("postal");

    private final String keyword;
    private AddressSubType(String keyword) {
        this.keyword = keyword;
    }
    public String getKeyword() {
        return keyword;
    }
    @Override
    public String toString() {
        return keyword;
    }
}

public enum EmailSubType {
    INTERNET("internet"), X400("x.400");

    private final String keyword;
    private EmailSubType(String keyword) {
        this.keyword = keyword;
    }
    public String getKeyword() {
        return keyword;
    }
    @Override
    public String toString() {
        return keyword;
    }
}

Is there a way for these enums to share the fields and methods (like a parent class)? I know that it’s not possible to extend enums. Thanks.

  • 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-06T09:52:06+00:00Added an answer on June 6, 2026 at 9:52 am

    You could create a Value class

    public class Value {
    
      private final String keyword;
    
      private Value(String keyword) {
        this.keyword = keyword;
      }
      public String getKeyword() {
        return keyword;
      }
      @Override
      public String toString() {
        return keyword;
      }
    }
    

    Then you can create Classes with public static final values like this :

    public class AddressSubType extend Value {
    
      public static final AddressSubType DOM = new AddressSubType("DOM");
      public static final AddressSubType INTL = new AddressSubType("intl");
      ...
    
      private AddressSubType(String keyword) {
         super(keyword);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an iOS app that uses a number of enums for valid values,
My Grails application has a large number of enums that look like this: public
I have a list of enums as follows: public enum EventID : uint {
I have a number of enums in my application which are used as property
I have a number input that should trigger jQuery on every change. To do
I have a number of classes and they are quite close to each other
We have a number of data objects that realize INotifyPropertyChanged to allow for WPF
I have a number of classes (more than 40), each one has a number
I have 46 rows of information, 2 columns each row (Code Number, Description). These
I have about 20 classes for different messages and this number are growing. Each

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.