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

  • Home
  • SEARCH
  • 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 8530381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:14:24+00:00 2026-06-11T09:14:24+00:00

I have a MyService interface with MyServiceImpl basic implementation. I wrap MyServiceImpl into a

  • 0

I have a MyService interface with MyServiceImpl basic implementation.
I wrap MyServiceImpl into a chain of MyService decorators.

For that i’ve created a MyServiceDelegate which is an abstract class taking a MyService instance and delegating all the service calls to the provided MyService instance.

But in my unit tests, for a specific need, i need to find back the first real implementation of the MyService, which is MyServiceImpl, and i only have a MyService which refers to a decorator.

I just wonder if it is possible with Guava, to make a recursion in a functional way that will return me the “original service” that has been decorated with a lot of layers and is not a delegate service.
I think of using a function like Function that returns the delegate service, or null if it’s the original service, but don’t know were to go with it.

I know i can easily do it with a while loop, and i’m not looking for an alternative solution. Just want to know if Guava can solve these kind of problems.

  • 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-11T09:14:25+00:00Added an answer on June 11, 2026 at 9:14 am

    You don’t even need a while loop or Guava. Just add the following method in your interface:

    public MyService undecorate();
    

    And then the following implementation in the delegate:

    return decoratedService.undecorate();
    

    And the following implementation in the “real” implementation:

    return this;
    

    If the interface can’t be modified, do it externally:

    public MyService undecorate(MyService service) {
        if (service instanceof MyServiceDelegate) {
            return undecorate(((MyServiceDelegate) service).getDecoratedService());
        }
        else {
            return service;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a WCF service interface and implementation in a Class Library. I
I have created a very basic service operation that needs to write content to
I have a WCF Service (called myservice.svc) that takes a message from a user
I have coded a service like that : public interface IMyInterface { ... }
I have the following code: public interface IService { } public class MyService :
I have created a WCF service which does not use the app.config to configure
Suppose I have a ASP.NET Web API controller that uses a service, which in
I have a WCF web service that defines IInterface interface. This interface declares two
Say I have the following interface that I want to share between my server
Have a look at following code: @Local public interface MyService { void printMessage(); }

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.