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

  • Home
  • SEARCH
  • 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 9119689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:27:21+00:00 2026-06-17T05:27:21+00:00

This is my overall workflow. First create an interface: public interface foo { void

  • 0

This is my overall workflow. First create an interface:

public interface foo {
   void bar(Baz b);
}

Then make, for example, a vector with different objects that all implement said interface:

myVector.add(new Ex);  //both Ex and Why implement foo.
myVector.add(new Why); 

And finally, use the interface:

for(int i=0; i<myVector.size(); i++) {
    myVector.get(i).bar(b);
}

However, for obvious reasons, this produces a compile time error:

The method bar() is undefined for the type Object

Casting won’t work because Ex and Why aren’t related. Try-catch casting to Ex and then Why is a horrible work-around. Making both Ex and Why extend Bar_doers also doesn’t sound succinct either, as that would be doing away with interfaces.

How can I perform operations that care about whether an Object implements a given interface, not whether an object is of a given class?

  • 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-17T05:27:22+00:00Added an answer on June 17, 2026 at 5:27 am

    You need to read about generics.

    Assuming you were using a standard Java container, then the solution in your case is to define myVector thus:

    List<foo> myVector = new ArrayList<foo>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first question in here, and I would like to ask if
I think this is my overall .NET inexperience speaking here, but I cannot figure
I've found that test first development can be painful if the workflow is slow.
I might be doing this wrong overall, but maybe someone will be able to
I'm hoping this is straightforward. I work on a large code-base, the overall quality
This is my xml output of service. <LifeAreas> <Overall i:nil=true/> <Career> <Good> <NamePlanet/> <NamePlanet/>
If I have an entity in RIA services like this, [EnableClientAccess] public class ShapeEntity
I would imagine that the overall answers to this will push me over to
I'm trying to reduce the overall height of this gridview so there aren't so
I have this in html code: <select name=t id=t> <option value=6>test2</option> <option value=0>Overall</option></select> <select

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.