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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:53:37+00:00 2026-06-03T08:53:37+00:00

I have a class Employee and a class Building . These classes are not

  • 0

I have a class Employee and a class Building.
These classes are not related to each other from class hierarchy perspective.
I need to process a bunch of Employee and Building objects and their results will end up in different lists.
So I have and interface e.g.

public interface Processor{  
  public void process(String s, List<?> result);  
}  

The idea is that the string s carries information related to either an Employee or a Building and the implementation after some processing adds to the result list either an Employee object or a Building object.
There are 2 implementations of Processor one is EmployeeProcessor and a BuildingProcessor.
Somewhere in the code I get a reference to either of these and I pass either a List<Employee> or a List<Building> to the process method.

Problem is that the code does not compile.
When I do e.g. inside the EmployeeProcessor : result.add(new Employee(a,b,c,d));
I get:

The method add(capture#2-of ?) in the type List is not
applicable for the arguments

I guess I can understand the problem, but I don’t want to change the interface to:

public interface Processor{  
  public process(String s, List result);  
}   

I.e. not specify type of list.
Is there a way around this problem? Is the interface definition wrong?
Note: this interface is part of implementation of Command pattern

  • 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-03T08:53:38+00:00Added an answer on June 3, 2026 at 8:53 am

    This is what I was thinking.

    interface Processor<T>{
        public void process(String s, List<T> result);
    }
    
    class BuildingProcessor implements Processor<Building>{
        @Override
        public void process(String s, List<Building> result) {
            result.add(new Building());
        }
    }
    
    class EmployeeProcessor implements Processor<Employee>{
        @Override
        public void process(String s, List<Employee> result) {
            result.add(new Employee());
        }
    }
    

    FYI, you can further limit the type. For example, if both Building and Employee classes implement, lets say, Processable, then you can do interface Processor<T extends Processable>

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

Sidebar

Related Questions

I have an abstract class Employee and 2 other classes that extend it (Developer
As a simplified example, I have the following data classes: public class Employee {
I want to have an abstract class Employee, and 2 derived classes; Staff and
I have class Employee which is something like this. class Emp { int EmpID;
I have a class (called Employee. non static) defined in a class library. I
I have a Employee class with many attributes. One of the attributes is employeeId
I have the following models class Person(models.Model): name = models.CharField(max_length=100) class Employee(Person): job =
I have a user defined class, say import java.util.Calendar; public class Employee{ private String
I have the following: MODEL.PY LIST = (('Manager', 'Manager'),('Non-Manager', 'Non-Manager'),) class Employee(models.Model): fname =
I have written this clone method for when the parent of the Employee class

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.