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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:57:09+00:00 2026-06-04T11:57:09+00:00

I have in mind an interface which declares a method for converting a raw

  • 0

I have in mind an interface which declares a method for converting a raw score from a survey to a percentile value for a particular category, where the categories are described by more than one otherwise unrelated enum types. So I started with this:

public interface NormTable<E extends Enum<E>> {
    Integer percentileForRawScore(E e, int score);
}

I’ve then got an implementing class for, say, the Foo survey and its Subscale enum:

public class FooSubscaleNormTable implements NormTable<Subscale> {
    public Integer percentileForRawScore(Subscale e, int score) {
        // Implementation
    }
}

And finally, a factory class for creating the appropriate concrete class:

public class NormTableFactory {
    public static <E extends Enum<E>> NormTable<E> normTableForSurveyAndType(
        String surveyCode, Class<E> clazz) {
    if ("Foo".equals(surveyCode) && Subscale.class.equals(clazz)) {
        return (NormTable<E>) new FooSubscaleNormTable();
    } else {
            // ...
        }
    }
}

I suspect the cast there is wrong, as Eclipse flags it as unchecked, though lets me carry on. The Java 1.6 compiler on the build server, however, is not happy at all and flags them as inconvertible types.

Have I got the signatures in the factory class wrong, or is my whole architecture looking suspect? I note above that the enum types are “otherwise unrelated”, though they all represent categories within surveys, and could conceivably implement an interface to unify their types. Would that help?

  • 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-04T11:57:11+00:00Added an answer on June 4, 2026 at 11:57 am

    You shouldn’t use a concrete Enum class in your declaring type.

    Make FooSubscaleNormTable generic as well

    public class FooSubscaleNormTable<E extends Enum<E>> implements NormTable<E> {
        public Integer percentileForRawScore(E e, int score) {
           if(e instanceof Subscale) {
               switch((Subscale) e) {
               case X:
               // do something
               break;
               }
           }
           // return 0; 
        }
    }
    

    and change your factory to

    public class NormTableFactory {
        public static <E extends Enum<E>> NormTable<E> normTableForSurveyAndType(
            String surveyCode, Class<E> clazz) {
        if ("Foo".equals(surveyCode) && Subscale.class.equals(clazz)) {
            return (NormTable<E>) new FooSubscaleNormTable<E>();
        } else {
                // whatever else
            }
        }
    }
    

    Then when you invoke it, that is when you pass in your desired enum type.

    NormTable<Subscale> scale = NormTableFactory.normTableForSurveyAndType("surveyCode", Subscale.class);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have something in my mind which have been bothering me for quite a
This is a syntax question. I have a generic class which is inheriting from
I have a generic interface hierarchy which describes some controllers for other generic types,
So what i have in mind is showing a list with most popular posts
Here is what I have in mind: 1) Create a service that will run
This is what I have in mind: Can anyone point out some relevant resources?
I'm new to Django, but the application that I have in mind might end
I'm new to c++ but have set my mind on a specific task that
I have a project in mind whose main selling point would be very good
I have a project in mind that will require the majority of queries to

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.