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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:40:42+00:00 2026-06-01T01:40:42+00:00

I am currently trying to achieve something like this: Based on this class, I

  • 0

I am currently trying to achieve something like this:
Based on this class, I try to create a new instance of the class Class<? extends AbstractValidator> returned by the method getValidator().

public abstract class AbstractEnumDefinition
       extends AbstractRequestFieldDefinition {

    private Vector<String> values = new Vector<String>();

    public abstract void define(String lang);

    protected void addEnumDefinition(String value){
        values.add(value);
    }

    public Vector<String> getValues(){
        return values;
    }

    @Override
    public Class<? extends AbstractValidator> getValidator() {
        return new AbstractValidator() {
            @Override
            public boolean isValid(String value) {
                return values.contains(value);
            }

            @Override
            public String getDefaultValue() {
                return "";
            }
        }.getClass();
    }
}

Say I create this class:

public class LanguageDefinition extends AbstractEnumDefinition {

    public LanguageDefinition() {
        super();
    }

    @Override
    public void define(String language) {
        addEnumDefinition("BEL-fr");
        addEnumDefinition("BEL-nl");
        addEnumDefinition("BEL-en");
    }
}

Later in my code, I call

new LanguageDefinition().getValidator().getConstructor().newInstance()

The class I am trying to instantiate here is not declared anywhere, but “generated dynamically”/”dynamically created” within the AbstractEnumDefinition class.

When trying to do this, I get an java.lang.InstantiationException for

be....servlets.model.extraction.filter.editor.AbstractEnumDefinition$1

I guess this is due to the fact that this Class has to be explicitly created before hand, and not referenced dynamically?

Is there some kind of solution that would allow me to not have to write one class per validator?

Thanks for the help,

Eric

  • 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-01T01:40:44+00:00Added an answer on June 1, 2026 at 1:40 am

    I can only make assumptions since i don’t see the code where you are actually using the class, but you should check: http://docs.oracle.com/javase/6/docs/api/java/lang/InstantiationException.html

    One thing it mentions is the instantiation can fail is the class is an abstract class (perfectly logical since you can’t instantiate abstract classes).

    Also, i don’t see why you need to return the class and then create and object. Why not just define a Validator Interface and have your method return a Validator object.

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

Sidebar

Related Questions

I'm trying to achieve something like the following in C++: class MyVector; // 3
I'm looking into windows management on OS X (trying to achieve something like WinSplit
I'm currently trying out db4o (the java version) and I pretty much like what
I'm currently trying to build a personal website to create a presence on the
I'm currently trying to pass a mono threaded program to multithread. This software do
I am new to ruby and currently trying to operate on each character separately
I'm trying to achieve something along the lines of... UserControl (MyRepeater) <p>Control Start</p> <asp:Repeater
I'm pretty new to ORMs, and I'm currently giving Telerik OpenAccess ORM a try
Currently I'm learning C++ and I've been trying to create a simple image processing
I have a webservice function that returns something like the following: New Orleans, Louisiana

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.