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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:23:48+00:00 2026-05-10T23:23:48+00:00

Suppose you’re maintaining an API that was originally released years ago (before java gained

  • 0

Suppose you’re maintaining an API that was originally released years ago (before java gained enum support) and it defines a class with enumeration values as ints:

public class VitaminType {  public static final int RETINOL = 0;  public static final int THIAMIN = 1;  public static final int RIBOFLAVIN = 2; } 

Over the years the API has evolved and gained Java 5-specific features (generified interfaces, etc). Now you’re about to add a new enumeration:

public enum NutrientType {  AMINO_ACID, SATURATED_FAT, UNSATURATED_FAT, CARBOHYDRATE; } 

The ‘old style’ int-enum pattern has no type safety, no possibility of adding behaviour or data, etc, but it’s published and in use. I’m concerned that mixing two styles of enumeration is inconsistent for users of the API.

I see three possible approaches:

  • Give up and define the new enum (NutrientType in my fictitious example) as a series of ints like the VitaminType class. You get consistency but you’re not taking advantage of type safety and other modern features.

  • Decide to live with an inconsistency in a published API: keep VitaminType around as is, and add NutrientType as an enum. Methods that take a VitaminType are still declared as taking an int, methods that take a NutrientType are declared as taking such.

  • Deprecate the VitaminType class and introduce a new VitaminType2 enum. Define the new NutrientType as an enum.
    Congratulations, for the next 2-3 years until you can kill the deprecated type, you’re going to deal with deprecated versions of every single method that took a VitaminType as an int and adding a new foo(VitaminType2 v) version of each. You also need to write tests for each deprecated foo(int v) method as well as its corresponding foo(VitaminType2 v) method, so you just multiplied your QA effort.

What is the best approach?

  • 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. 2026-05-10T23:23:49+00:00Added an answer on May 10, 2026 at 11:23 pm

    Personal opinion is that it’s probably not worth the effort of trying to convert. For one thing, the ‘public static final int’ idiom isn’t going away any time soon, given that it’s sprinkled liberally all over the JDK. For another, tracking down usages of the original ints is likely to be really unpleasant, given that your classes will compile away the reference so you’re likely not to know you’ve broken anything until it’s too late (by which I mean

    class A    {        public static final int MY_CONSTANT=1    }     class B    {            ....            i+=A.MY_CONSTANT;     } 

    gets compiled into

    i+=1 

    So if you rewrite A you may not ever realize that B is broken until you recompile B later.

    It’s a pretty well known idiom, probably not so terrible to leave it in, certainly better than the alternative.

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

Sidebar

Ask A Question

Stats

  • Questions 93k
  • Answers 93k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This question is somewhat incomplete, because a proper answer would… May 11, 2026 at 6:35 pm
  • Editorial Team
    Editorial Team added an answer I found the problem, and it doesn't seem to be… May 11, 2026 at 6:35 pm
  • Editorial Team
    Editorial Team added an answer Two options: First is ActivePresenter which works well for this.… May 11, 2026 at 6:35 pm

Related Questions

Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
Suppose you have 2 different ASP.NET applications in IIS. Also, you have some ASCX
Suppose you're developing a software product that has periodic releases. What are the best
Suppose you have a full path to an accessible file or folder on the
Suppose you have the following string: white sand, tall waves, warm sun It's easy

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.