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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:50:12+00:00 2026-06-07T14:50:12+00:00

I was wondering if it was possible to set a parameter to a method

  • 0

I was wondering if it was possible to set a parameter to a method as an Object, which must be a extend one class and implement another. Here is an example: Let’s say I have a class called ClassA and an interface called MyInterface.

public class ClassA {
    /* code */
}    


public interface MyInterface {
    /* code */
}

Let’s say somewhere else there is a class called ClassB, which both extends ClassA and implements MyInterface.

public class ClassB extends ClassA implements MyInterface {
    /* code */
}

I could also have a ClassC, which also extends ClassA and implements MyInterface:

public class ClassC extends ClassA implements MyInterface {
    /* code */
}

My question is this:

Let’s say I have a method called method1, and in method1 I want to have a parameter which accepts an Object. Let’s say I wanted this Object to either subclass ClassA or actually be ClassA itself. This is easy to do:

 public void method1(ClassA parameter) {

 }

Let’s say I also wanted a method2, and in method2 I want to have a parameter which accepts anything which implements MyInterface. Again, this is easy:

 public void method2(MyInterface parameter) {

 }

But what if I wanted a method3, and I wanted to have a parameter which accepts only objects which either subclass ClassA or is ClassA itself, AND implements MyInterface, and so will accept both ClassB and ClassC, but not any class which only extends ClassA, or only implements MyInterface, or neither. Like:

public void method3 ([Something that extends ClassA implements MyInterface] parameter) {
  /* code */
}
  • 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-07T14:50:13+00:00Added an answer on June 7, 2026 at 2:50 pm

    You can do the following:

    public <A extends ClassA & MyInterface> void method3(A parameter) { ... }
    

    But I don’t think it’s a good idea – if you have a concept of object that extends ClassA and implements MyInterface, it would be better to create a separate class or interface to represent that concept.

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

Sidebar

Related Questions

Just wondering if it is possible to set a ribbon rule which shows/hides a
I was wondering if it is possible to set up an app that will
I'm wondering how to set the max possible time limit for a php page,
i was wondering if it was possible to filter which action is invoked based
Is it possible to implement parameter value tab expansion for enum parameter types? Creating
I am wondering whether its possible to change/set/delete my session variable AS A USER.
I'm wondering.. 1)is it possible to set an imageview's resource to the URL location
I was wondering if it was possible to set the IPhone's background image from
I'm wondering is it possible somehow? sample code class CustomFilter { ... function FilterData($data,
i am using Jackson and was wondering if it is possible to set global

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.