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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:30:49+00:00 2026-05-26T21:30:49+00:00

I design a class: public class CustomEvent< P, T > { /** Facade interface

  • 0

I design a class:

public class CustomEvent< P, T >
{
  /** Facade interface used for adopting user interfaces to our generic class. */
  public interface ICaller< P, T >
  {
    /** callback facade method. */
    void call( P parent, T callback, Object... objects );
  }

  /** Abstract class for simplifying naming in constructor.  */
  public abstract class Caller implements ICaller< P, T >{}

  /** Constructor. */
  public CustomEvent( final String name, final P parent, final Caller caller ){}
}

Now I want to create a instance of such class:

  public class TestClass
  {
    private final TestEvent mEventOnLoad;

    public TestClass()
    {   
      // ERROR here: No enclosing instance of type CustomEvent<P,T> is accessible. 
      // Must qualify the allocation with an enclosing instance of type 
      // CustomEvent<P,T> (e.g. x.new A() where x is an instance of CustomEvent<P,T>).
      mEventOnLoad = new TestEvent( "onLoad", this, new TestEvent.Caller() {
        public void call( TestClass parent, ITestCallbacks callback, Object... objects )
        {
          // some code here
        }
      } );
    }

    private class TestEvent extends CustomEvent< TestClass, ITestCallbacks >
    {
      public TestEvent( String name, TestClass parent, TestEvent.Caller caller )
      {
        super( name, parent, caller );
      }
    };
  }

Is it possible to somehow to workaround that? I want to simplify naming of the classes, instead of long generic declaration use short abstract class name which contains all needed type definitions?

I have a filling that it is possible… but I’m not very comfortable with Java yet…

Solution

    private class TestEvent extends CustomEvent< TestClass, ITestCallbacks >
    { 
      public final static TestEvent Instance = new TestEvent( null, null, null );

      public TestEvent( String name, TestClass parent, TestEvent.Caller caller )
      {
        super( name, parent, caller );
      }
    };

    public TestClass()
    {   
      mEventOnLoad = new TestEvent( "onLoad", this, TestEvent.Instance.new Caller() {
        public void call( TestClass parent, ITestCallbacks callback, Object... objects )
        {
          // some code here
        }
      } );
    }
  • 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-26T21:30:49+00:00Added an answer on May 26, 2026 at 9:30 pm

    If you’re just trying to get your code to compile (mind you, you’d need to fix several issues with type safety and parameterising), try something like this:

    public TestClass() {
        CustomEvent bla = new CustomEvent("name", null, null); // TODO: parameterise
        mEventOnLoad = new TestEvent("onLoad", this, bla.new Caller() {
            @Override
            public void call(Object parent, Object callback, Object... objects) {
                // some code here
            }
        });
    }
    

    What the error message was trying to say is that you need an instance (bla) to call new on. I’d suggest reading up on inner classes a bit 😉

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

Sidebar

Related Questions

Which class design is better and why? public class User { public String UserName;
I have the following code for factory design pattern implementation. class Pen{ public: virtual
A brief preface: I'm in a game design class where our project for the
I will explain my class design public class A { public Ilist<B> Something {
In Java, it is very easy to code the following design: public abstract class
I am trying to design a helper class that implements methods using AsyncTask. public
I am thinking of the following design: static class AppVersion { public static string
I've seen this question: Class design with vector as a private/public member? , but
Sometimes, I came across some class design as follow. abstract class animal { public
hey everyone... so i'm working on a database design class for university. I've got

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.