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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:58:45+00:00 2026-06-10T01:58:45+00:00

I have a service locator class called DMSServiceLocator.class, I have a method within it

  • 0

I have a service locator class called DMSServiceLocator.class, I have a method within it called getParser() with a return type called Parser. I’m trying to return a service called AutoMateParser with an Impl that extends Parser, however I’m getting a compiling error saying Parser is required, found AutoMateParser. When I return new AutoMateServiceImpl() rather than my service interface, I receive no compiling errors. It doesn’t appear my getParser() method realizes autoMateParser is of the same type. I tried casting AutoMateParser with Parser, “return (Parser) autoMateParser;” which resolved compiling errors, but received a cast exception. I’m wondering if anybody knows how to do this. Thanks in advance.

below is a sample of my code.

AppModule.class

public static void bind(ServiceBinder binder) {
        binder.bind(AutoMateParser.class, AutoMateParserImpl.class);
}

DMSServiceLocator.class

public class DMSServiceLocator {

    @Inject
    private AutoMateParser autoMateParser;

    public Parser getParser() {
        if(automate) {
        return autoMateParser();
        } else {
           //Different data scrubber, but also extends Parser
           return homenetParser();
        }
    }

}

AutoMateParserImpl.class

public class AutoMateParserImpl extends Parser implements AutoMateParser {
    protected Vehicle parseCar(String vehicleData) {
        //some data scrubbing code
    }
}

Parser.class

public abstract class Parser {
    //some csv line reader code
    protected abstract Vehicle parseCar(String carData);
}
  • 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-10T01:58:47+00:00Added an answer on June 10, 2026 at 1:58 am

    You are trying to return an object of type AutoMateParser. That interface is not a sub-type of Parser (only AutoMateParserImpl is), hence the compiler complains. You’ll need to re-think your class hierarchy.

    You could extract a Parser interface with the parseCar method, have AutoMateParser extend that interface, create an abstract ParserImpl class implementing the Parser interface, and have your service locator return the Parser interface type instead of the abstract implementation.

    Edit: The types could look something like this:

    public interface Parser {
       //public methods that you need to call
    }
    
    public interface AutoMateParser extends Parser {
        //any extra or overriden method declarations
    }
    
    public abstract class AbstractParser implements Parser {
        //common code and implemented methods
        protected abstract Vehicle parseCar(String carData);
    }
    
    public class AutoMateParserImpl extends AbstractParser implements AutoMateParser {
        //any extra or overriden method implementations defined in AutoMateParser
        protected Vehicle parseCar(String vehicleData) {
            ...
        }
    }
    
    public class DMSServiceLocator {
    
        @Inject
        private AutoMateParser autoMateParser;
        //more services
    
        public Parser getParser() {
            if(automate) {
               return autoMateParser();
            } else {
               //Different data scrubber, but also extends Parser
               return homenetParser();
            }
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

DISCLAIMER: I know there is debate between DI and service locator patterns. I have
I have service url : please check it , It's return json string. I
I currently have service classes that look something like this public class UserService :
I have a service returning an array of type BaseItem. BaseItem has N subtypes.
I have a service: [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)] public class PremieraInteraction :
Cannot validate this method because the domain mapping for the return type (XXXProxy) could
I have a framework with a DDD data layer which uses the service locator
Consider the code below (which has been simplified). I have a service class that
I start an activity in my class Locator.java which starts a locacionListener Service. That
I have some problem with calling web service from flex. I have service with

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.