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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:12:03+00:00 2026-05-23T12:12:03+00:00

I have the following enum in a Java class: public enum Resolution { RES_32

  • 0

I have the following enum in a Java class:

public enum Resolution {
    RES_32 (32),
    RES_64 (64);
    private final int asInt;
    private Resolution(int asInt) {
        this.asInt = asInt;
    }
};

I have more classes that need a similar kind of enum, with the same asInt property and the same constructor, but with different constants. So, in another class, I need the following enum:

public enum Resolution {
    RES_32 (32),
    RES_64 (64),
    RES_128 (128);
    private final int asInt;
    private Resolution(int asInt) {
        this.asInt = asInt;
    }
};

If this was a class, I could use inheritance to not repeat the code in the constructor (and would likely have made a getter for that asInt property). What can I do in order to stop repeating myself each time I need such a Resolution enum? Ideally, I would like to just specify the constants for each Resolution, and to have the constructor and property kept.

  • 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-23T12:12:04+00:00Added an answer on May 23, 2026 at 12:12 pm

    EnumSet may be helpful in this context. Given the following,

    public enum Resolution {
    
        RES_32(32),
        RES_64(64),
        RES_128(128),
        RES_256(256);
    
        public static Set<Resolution> deluxe = EnumSet.allOf(Resolution.class);
        public static Set<Resolution> typical = EnumSet.range(RES_64, RES_128);
        public static Set<Resolution> ecomomy = EnumSet.of(RES_32);
    
        private final int asInt;
    
        private Resolution(int asInt) {
            this.asInt = asInt;
        }
    };
    

    Suitably named sets may be used as shown below.

    for (Resolution r : Resolution.deluxe) {
        System.out.println(r.asInt);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's assume we've got the following Java code: public class Maintainer { private Map<Enum,
I have the following enum: public enum Status implements StringEnum{ ONLINE(on),OFFLINE(off); private String status
I have the following class: public class ErrorMessage { public enum Severity { Error,
I have the following enum and POCO class public enum Gender { Male, Female,
So, say I have the following enum declaration: public class WatchService implements Runnable {
I have the following enum declared: public enum TransactionTypeCode { Shipment = 'S', Receipt
I have the following enumeration: public enum AuthenticationMethod { FORMS = 1, WINDOWSAUTHENTICATION =
I have an interface like the following: package example; import java.awt.Point; public interface Thing
I'm writing some Enum functionality, and have the following: public static T ConvertStringToEnumValue<T>(string valueToConvert,
I'm writing some Enum functionality, and have the following: public static T ConvertStringToEnumValue<T>(string valueToConvert,

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.