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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:37:21+00:00 2026-05-25T11:37:21+00:00

I want to develope a class in java. The problem is that the constructor

  • 0

I want to develope a class in java. The problem is that the constructor doesn’t work

The class is this:

public class EnumSetPlus<E extends Enum<E>> { 

//Map
private EnumSet<E> map;

//Constructor
public EnumSetPlus(){

}

I want to inicializate the map with EnumSet.noneOf(E.class) but the constructor gives an error.

Is the constructor wrong?. Can I initialize the variable map without a constructor?.

I have tried public EnumSetPlus<<E extends Enum<E>>> = EnumSet.noneOf(E) in the variable context, but it doesn’t work.

I have tried map = EnumSet.noneOf(E.class) into the constructor too, but neither it works.

I think it’s a problem with the syntax or with the method

could you help me?

Thanks beforehand!

  • 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-25T11:37:22+00:00Added an answer on May 25, 2026 at 11:37 am

    The problem is that you need a class instance of E which can’t be done with just using E or E.class. Try and provide a Class<E> as a constructor parameter, in order to tell the class which enum class it is parameterized for.

    This should work:

    public EnumSetPlus(Class<E> clazz){
      map = EnumSet.noneOf(clazz);
    }
    

    The problem is that the compiler doesn’t know of what type E actually is (which enum it is), thus it can’t resolve the class at compile time. You need to make that information available at runtime, either with the parameter as suggested or by subclassing EnumSetPlus along with a concrete type parameter which then can be determined using reflection. Since the reflection approach would be overkill in that simple case, I’d suggest trying the parameter approach.

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

Sidebar

Related Questions

I occasionally get this problem, and generally work around it, but it's rather frustrating.
I want to use a temp directory that will be unique to this build.
I want to develop Java apps, real quick, what IDE should I choose?
I want to develop a mobile web application using asp.net 3.5 that can be
Imagine that you want to develop a non-trivial end-user desktop (not web) application in
I want a rule that checks that fields and classes are properly annotated with
I got to know about this Java 1.5 capability recently and I developed a
I'm using Netbeans to develop a Java application and I want to create a
Every time that I want to do a Layout, I'm getting a black layout
Hello all and thanks for the attention! I have a problem that must both

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.