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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:59:05+00:00 2026-05-23T20:59:05+00:00

I have code like: class Entity; class EntityTool extends Entity; class EntitySprite extends Entity;

  • 0

I have code like:

class Entity;

class EntityTool extends Entity;
class EntitySprite extends Entity;

class EntityToolSpoon extends EntityTool;
class EntityToolBow extends EntityTool;
class EntitySpritePlayer extends EntitySprite;
class EntitySpriteMonster extends EntitySprite;

Now I have a method called move() in Entity, and some others overwrite it.

Now, if the argument is an EntitySpriteMonster, why does this not work:

public void foonction(Object wut)
{
    if (wut instanceof Entity) ((Entity)wut).move(x,y);
}

The move function (though this is redundant and unneeded. it fails at if rawpeek instanceof...):

@Override
public void move(double x, double y) {
    super.move(x, y);
    for (int i=0; i<8; i++) {
        Object rawpeek = palette.get(i);
        System.out.println(rawpeek);
        if (rawpeek == null) continue;
        if (rawpeek instanceof Entity)
            ((Entity) rawpeek).move(x, y);
    }
}

EDIT: It just aborts. (operator instanceof returns false)

Eclipse shows me in debug, that wut is definetly an EntitySpriteMonster.

  • 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-23T20:59:07+00:00Added an answer on May 23, 2026 at 8:59 pm

    Problem solved!

    The above use of instanceof was correct.
    The problem instead was:

    ((Inventory)palette).get(index) returned an InventorySlot, and not a Entity. InventorySlot contains Entites, so I was missing to peek the first item from the container.

    My correct code should be Object rawpeek = paltte.get(i).peek();

    Thanks everyone for trying. And sorry for this obvious problem.

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

Sidebar

Related Questions

I have some code that I use with Entity Framework like class Person{ pubic
I have code like: @Entity @Table(name = A) @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) public class A
I have the following code: modelBuilder.Entity<User>().HasMany(x => x.Items).WithRequired(); The model looks like public class
Suppose I have code like this: template<class T, T initial_t> class Bar { //
Say I have some code like namespace Portal { public class Author { public
I have a data structure that represents C# code like this: class Namespace: string
I have a ton of repeating code in my class that looks like the
Using NHibernate.Mapping.Attributes, I have a entity class with something like: [Class] public class EntityA
In our application, I have seen code written like this: User.java (User entity) public
I have an entity called Incident and a DTO called IncidentDTO . For now,

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.