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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:59:46+00:00 2026-05-12T16:59:46+00:00

Let me describe the situation, and I’m sure I’m just thinking about this problem

  • 0

Let me describe the situation, and I’m sure I’m just thinking about this problem incorrectly. I have a concrete class that will implement an interface. I want to enforce in the contract that the class must have a constructor with a specific type. So for instance:

interface MyInterface {}
public class MyClass implements MyInterface {
    public MyClass(HashMap<String, String> params) {

    }
}

I want to ensure that MyClass is instantiated with a single HashMap argument, which seems like it would be done something like this:

interface MyInterface<T>

Other than using generics on method signatures, I’ve never used them with classes or interfaces, and I’m really a beginner with that, so please explain any generics involved with the solution… or the alternative solution if I’m thinking about this incorrectly (architecturally speaking). Thanks!

  • 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-12T16:59:46+00:00Added an answer on May 12, 2026 at 4:59 pm

    You can’t enforce a contract on constructor using interface in Java. The best approximation you could get is by defining an interface for a factory, with a create() method that takes a single HashMap…

    Also you can replace the interface with an abstract class for which the constructor requires an HashMap, that will force sub classes to give one, but not more (the sub classes will not necessarily have an HashMap parameter).

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

Sidebar

Related Questions

I've got a strange problem. Let me first describe my situation: Webserver01 (Webapplication, SQL,
Let me describe the situation I am trying to do: I have a list
Let me start off by describing my situation. I have a main view that
Let me describe my situation: We are developing a web application that creates websites.
This is a difficult problem to describe so please let me know if anything
I realize that similar questions have been asked about this before here on SO,
I have about 50 CGPoint objects that describe something like a path, and I
Let me first describe my situation. I have a list of Hex values, which
Let me describe the problem and the solution i currently have and maybe you
Let me describe the behavior I get: Load a user from the database: this

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.