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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:45:23+00:00 2026-05-30T23:45:23+00:00

I want my class to implement an interface, but I want to provide the

  • 0

I want my class to implement an interface, but I want to provide the implementation of the methods using ITD in an aspect. Is this possible?

Interface:

public interface CloningService<T> {
    public T clone(T object);
}

Default implementation:

public class DefaultCloningServiceImpl implements CloningService<T> {
    public T clone(T object) {
        // implementation of the clone method
    }
}

Specific implementation:

public class PersonService implements CloningService<Person> {
    // no code (!)
}

The class PersonService would declare that it implements the CloningService interface, but the actual implementation of the methods would be provided in DefaultCloningServiceImpl and an aspect would introduce them to PersonService.

I followed the example on Eclipse.com and I tried to use @DeclareParents to achieve the above functionality. However, I was getting a compiler error from AspectJ, which had to do with generics. It’s as if the @DeclareParents annotation did not expect the generics to be used…

Thank you.

  • 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-30T23:45:24+00:00Added an answer on May 30, 2026 at 11:45 pm

    I’d recommend that you use code style aspectj to solve this rather than annotation style.

    This could be done simply by having an aspect like this:

    aspect CloningServiceAspect {
      declare parents : PersonService extends DefaultCloningServiceImpl<Object>;
    }
    

    To make this more general and attached to an annotation, you can do something like this:

    aspect CloningServiceAspect {
      declare parents : (@CloningService *) extends DefaultCloningServiceImpl<Object>;
    }
    

    And if you wanted to package this up into a standalone jar, just make sure to add all code that you want to weave adds this jar to its aspect path (if using compile-time weaving).

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

Sidebar

Related Questions

I would like a class to implement an interface, I do not want to
I want to implement a derived class that should also implement an interface, that
as I am implementing the ICollection-Interface in my class I want to implement the
This is the class I want to implement the onClickListener in: private void updateUserListView(DatabaseHandler
I want to implement a function in the base class but I also want
I want to implement a custom trace listener like follows: public class TraceListener :
I have an interface IFoo for which I want to provide a default implementation
I want to have a class which implements an interface, which specifies the specific
I have a class that instantiates two classes which implement interfaces. I want one
I want to implement a class which can be used by two classes of

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.