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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:03:00+00:00 2026-06-07T16:03:00+00:00

I have a method on which I need to pass an enum as a

  • 0

I have a method on which I need to pass an enum as a parameter.

public <T> T doSomething(SomeEnum operation, Class<T> something);

I have several enums and the method is a common one which should work with any enums. What is the correct way to write this method signature to accept any generic enum types? I know that I can use a marker interface to this purpose, but I would like to write it with generic enum signatures. Please advise me on this.

Whats the bad idea with the below one: (It works but I get warnings from IDE saying it is a raw type. I’m not clear about the reason).

 public void doSomething(Enum operation);
  • 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-07T16:03:02+00:00Added an answer on June 7, 2026 at 4:03 pm
    public <E extends Enum<E>> void doSomething(E operation);
    

    EDIT: An example according to your modifications:

    public class Main {
    
        public enum Day {
            SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
            THURSDAY, FRIDAY, SATURDAY 
        }
    
        public <E extends Enum<E>> E doSomething(E operation, Class<E> klazz) {
    
            return operation;
        }
    
        public static void main(String[] args) {
    
            new Main().doSomething(Day.FRIDAY, Day.class);
        }
    
    }
    

    EDIT2:

    if you need T and the Enum as separate types, then you’ll need:

    public <T, E extends Enum<E>> T doSomething(E operation, Class<T> klazz) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method that uses a list which I need to pass into
I have a method within which I need to pass an ever-increasing integer to
I have jagged array which I need to pass to external method. [DllImport(...)] private
I have a method myButtonAction which performs some heavy calculations, which I need to
I have a method which returns single word as a String. I need to
i have a string and i need a utility method which looks for bad
I have a method I need to unit test, which as the subject implies,
Hi I have a helper method, which returns a string, where i need to
I have a method which i want to convert to Extension Method public static
I have a method which have this signature public static IList<T> GetBy<T>(System.Linq.Expressions.Expression<Func<T, bool>> expression)

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.