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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:09:42+00:00 2026-06-15T06:09:42+00:00

Interface A and its implementation: public interface A<K, E> { public void foo(); }

  • 0

Interface A and its implementation:

public interface A<K, E> {
    public void foo();
}

public abstract class AImpl<K, E> implements A<K, E> {
    public void foo(){};
}

Interface B, which extends interface A, and its implementation:

public interface B extends A<Integer, String> {
    public void bar();
}

public class BImpl extends AImpl<Integer, String> implements B {
    public void bar(){};
}

An abstract class C, which gets A injected:

public abstract class C<K, E> {
    A<K, E> a;

   @Inject
   public setA(A<K, E> a){
       this.a = a;
   }

   public A<K, E> getA(){
       return a;
   }
}

With Guice:

bind(new TypeLiteral<A<Integer, Book>>(){}).to(BImpl.class);

And the last class, which extends class C:

public class D extends C<Integer, String> {
   public void fooBar(){
        this.getA().bar(); //Gets BImpl injected by Guice, and call bar():  Not working - error
        ((B) this.getA()).bar(); //Working
   }
}

Like you can see from inline comments, BImpl gets properly injected and can be used, if it has no additional methods, that extends A (interface B is empty). If I add any new method in B, I can’t call it in D without it casting to B. My main goal is, giving a user possibility to extend A and use this functionality in D.

  • 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-15T06:09:42+00:00Added an answer on June 15, 2026 at 6:09 am

    If I add any new method in B, I can’t call it in D without it casting to B. My main goal is, giving a user possibility to extend A and use this functionality in D.

    If the user needs the functionality provided by B but not A, they should declare that they need a B. Class D should declare what it needs – not rely on casting to make sure it was correctly configured beyond what was declared.

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

Sidebar

Related Questions

Let's say I have a method public void Foo(string bar) that the caller should
I have public interface IRepository<T> where T : EntityBase { } and its implementation,
I have an interface @PersistenceCapable public interface MyInterface { public abstract String getName(); public
interface IExecutor { void Execute(); } class Executor2<T> where T : IExecutor { public
How to use Ninject with a sample code for interface and its implementation like
Given a basic repository interface: public interface IPersonRepository { void AddPerson(Person person); List<Person> GetAllPeople();
The interface for service layer is : EMS.java: public interface EMS extends UserDetailsService {
Imagine an implementation of the IDisposable interface, that has some public methods. If an
Suppose I have an interface for a service: public interface IFooService { void DoSomething();
I have the following POCO Class with its Repository Pattern Implementation. If my model

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.