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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:00:20+00:00 2026-06-16T21:00:20+00:00

I have some base class Entity . I want to allow users of Entity

  • 0

I have some base class Entity. I want to allow users of Entity to create instances of Entity that extend some given super class T (as if Entitys declaration was Class Entity extends T). I’m not aware of what T actually is, so I want Entity to be modular in that respect. If that’s not possible I’m ok with Entity implementing a given interface T as well.

Things like public class Entity<T> extends T and public class Entity<T> implements T do not work. (“Cannot refer to the type parameter T as a supertype”).

So my questions are:

1) is this at all possible to achieve in java ? some other language ?

2) if so, how ?

3) usually when java puts up hurdles like that it means something is wrong with my design, so how would you create this functionality (I guess what I’m looking for is basically multiple inheritance from Entity and T, can this be done ?).

EDIT: clarification – I want to achieve mixin type behavior while requiring as little as possible from the caller (creating a subclass of T which delegates calls to an Entity instance would demand way too much from the caller). is there no other way to do this ?

  • 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-16T21:00:21+00:00Added an answer on June 16, 2026 at 9:00 pm

    Java doesn’t support multiple inheritance; a given class can’t be a direct subclass of more than one class.

    However, if Entity is an interface, you can do it using an intersection bound.

    For example, to code a method that accepts an instance that is a subclass (not necessarily a direct subclass) of SomeClass and that implements Entity:

    public <T extends Entity & SomeClass> void doSomething(T t) {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume some domain and view objects (that have no common base class) public class
I have three general repository that handle three base classes: public class Entity {
I have a base class which is a Riak entity, and some derived classes
I have a base class that has some functionality that uses type inference... public
I have some classes that implement a generic base type. i.e: public class TreeItem<TEntity>
I have a base and derived class. The base class constructors have some static
I have a base class called Panel, where some information about a window is
I am writing some unit test and I have a unit testing base class
Lets say we have some basic AR model. class User < ActiveRecord::Base attr_accessible :firstname,
I have a Base Router where i define some functions that need to be

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.