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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:59:00+00:00 2026-06-10T22:59:00+00:00

Suppose I have interfaces as follows: public interface UnaryFunction<Ret, Arg> { public Ret invoke(Arg

  • 0

Suppose I have interfaces as follows:

public interface UnaryFunction<Ret, Arg> {
    public Ret invoke(Arg arg);
}

public interface BinaryFunction<Ret, Arg1, Arg2> {
    public Ret invoke(Arg1 arg, Arg2 arg);
}

Now suppose I have a wrapper class like so:

public class ConstructorWrapper<Ret> {
    // Wrapper for a java.lang.reflect.Constructor
    private final Constructor<Ret> constructor;

    // Try blocks in the following elided for brevity

    // Trying to implement UnaryFunction<Ret, Arg> with this
    public <Arg> Ret invoke(Arg arg) { return constructor.newInstance(arg); }

    // Trying to implement BinaryFunction<Ret, Arg1, Arg2> with this
    public <Arg1, Arg2> Ret invoke(Arg1 arg1, Arg2 arg2) { return constructor.newInstance(arg1, arg2); }
}

How do I change this so that ConstructorWrapper is declared to implement both UnaryFunction and BinaryFunction? Better yet, how do I make it so that passing in a one-argument constructor results in a ConstructorWrapper object (or subclass therein) that only implements UnaryFunction and passing in a two-argument constructor results in a ConstructorWrapper object that only implements BinaryFunction (ie. so you don’t pass in a unary constructor in a place where a BinaryFunction is expected)? Preferably with as little repetition as possible?

  • 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-10T22:59:01+00:00Added an answer on June 10, 2026 at 10:59 pm

    What is wrong with:

    public class ConstructorWrapper<Ret, Arg, Arg1, Arg2>
      implements UnaryFunction<Ret, Arg>, BinaryFunction<Ret, Arg1, Arg2>
    

    What is wrong with having a class provide both APIs?

    If you don’t have both, make that two wrappers. They can have an abstract superclass if you want to reduce code duplication. But if you want type safety, the wrapper classes should implement the interfaces!

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

Sidebar

Related Questions

Suppose I have an interface like so public interface Foo<Ret, Arg> { public Ret
Suppose I have these interfaces: public interface I1 { void foo(); } public interface
Suppose I have a few definitions like so: public interface ICategory { int ID
Suppose I have this annotation @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Name { String value(); }
I have a interface as follows public interface IX { void MethodA(); void MethodB();
Suppose you have a generic interface and an implementation: public interface MyInterface<T> { void
Suppose I have a pure virtual method in the base interface that returns to
Suppose I have created a UIView , MyView , in Interface Builder, and I
Suppose I'm implementing an MVP pattern and I have a view interface as such:
Suppose you have a COM interface ICOMInterface that is implemented by coclasses Coclass1 and

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.