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

The Archive Base Latest Questions

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

I am trying pass an enum into a method, iterate over that enums values,

  • 0

I am trying pass an enum into a method, iterate over that enums values, and call the method that that enum implements on all of those values. I am getting compiler errors on the part “value.getAlias()”. It says “The method getAlias() is undefined for the type E” I have attempted to indicate that E implements the HasAlias interface, but it does not seem to work. Is this possible, and if so, how do I fix the code below to do what I want? The code below is only meant to show my process, it is not my intention to just print the names of the values in an enum, but to demonstate my problem.

public interface HasAlias{ String getAlias(); };

public enum Letters implements HasAlias
{
   A("The letter A"),
   B("The letter B");

   private final String alias;

   public String getAlias(){return alias;}

   public Letters(String alias)
   {
     this.alias = alias;
   }

}

public enum Numbers implements HasAlias
{
   ONE("The number one"),
   TWO("The number two");

   private final String alias;

   public String getAlias(){return alias;}

   public Letters(String alias)
   {
     this.alias = alias;
   }

}

public class Identifier
{
   public <E extends Enum<? extends HasAlias>> void identify(Class<E> enumClass)
   {
      for(E value : enumClass.getEnumConstants())
      {
         System.out.println(value.getAlias());
      }
   }
}
  • 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-15T09:05:04+00:00Added an answer on June 15, 2026 at 9:05 am

    Here is how you bound a type to an enum that implements HasAlias:

    <E extends Enum<E> & HasAlias>
    

    Once you make thus change, the rest will work.

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

Sidebar

Related Questions

I'm trying to make a function that can take an enum type, display all
Trying to pass some values into an imagebutton click event, something like this: <asp:ImageButton
Im trying to pass some values into a text box from a child page
When trying to pass a CGPoint to a method the point is passed, but
im trying to pass back from a user control a list of strings that
Trying to pass the values but not making progress. Scenario : Have a public
I'm getting the following exception trying to pass an object through wcf: There was
I am trying pass a new variable into a template within django-registration. Here is
So I am trying pass in parameters to my buttonClicked function so that I
I have a tree structure that I am trying to use a recursive method

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.