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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:50:13+00:00 2026-06-08T00:50:13+00:00

I have a primitive collision system which checks every pair of objects to see

  • 0

I have a primitive collision system which checks every pair of objects to see if they are colliding.

int size = drawables.size();
for(int i = 0; i < size; ++i)
{
    for(int j = i+1; j < size; ++j)
    {
        Drawable drawable = drawables.get(i);
        Drawable drawable2 = drawables.get(j);
        if(CollisionDetector.areColliding(drawable, drawable2))
        {
            CollisionHandler.handleCollision(drawable, drawable2);
        }
    }
}

The CollisionDetector and CollisionHandler both have generic and specific versions of their respective functions, e.g.

public static boolean handleCollision(Drawable drawable1, Drawable drawable2)
public static boolean handleCollision(Player player, SolidRectangle rectangle)
public static boolean handleCollision(Player player, Snowflake snowflake)

where Player, SolidRectangle, and Snowflake all extend Drawable. I would like the above loop to call the most specific version of each method available, but currently it will only call the one for the superclass Drawable. Is there some way to do this without manually checking what the classes are via instanceof?

I could see how this might not be possible from the following example: If B extends A and C extends A and I write the methods

public void foo(A a, C c)
public void foo(B b, A a)

then have

A objectB = new B();
A objectC = new C();
foo(objectB, objectC);

that the call of foo would be ambiguous, but I hope someone might have more insight into the matter than I do. Is there any way to get around this?

  • 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-08T00:50:14+00:00Added an answer on June 8, 2026 at 12:50 am

    The Visitor Design Pattern offers an alternative to multiple dispatch in Java.

    Besides this, there are a few alternatives:

    There is an outdated MultiJava Project that implemented mutiple dispatch support in Java and there are a couple of other projects out there using reflection to support multimethods in Java: Java Multimethods, Java Multimethods Framework. Perhaps there are even more.

    You could also consider an alternative Java-based language which does support multimethods, like Clojure or Groovy (these links point to examples).

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

Sidebar

Related Questions

If you have an array of Java objects which have a primitive type (for
.NET we have primitive datatypes like int and value types like struct. And also
I have a struct Primitive, which has the following definition: typedef struct Primitive {
I have in input, which could be a single primitive or a list or
I have a Java primitive type at hand: Class<?> c = int.class; // or
I have a multi-byte primitive type called s32 which I want to read from
Are the primitive data types like int & short thread-safe in Java? I have
I have a number of one dimension arrays of Object[] (these objects are primitive
I have java primitive int and its wrapper Integer ,do it mean that the
I have a base class, Primitive , from which I derive several other classes--

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.