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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:55:39+00:00 2026-06-11T23:55:39+00:00

I have an arraylist of entities. The Entity class has public void update(int delta,

  • 0

I have an arraylist of entities. The Entity class has

public void update(int delta, Level level, ArrayList<Entity> entities){
    //do stuff
}

a subclass of entity, Player, has a function overriding it

public void update(int delta, Level level, ArrayList<Entity> entities){
    //do player specific stuff
    super.update(delta, level, entities);
}

when I call the player objects update function from an arraylist of entities, like this:

for(Entity entity : entities)            //contains an object of Player
    entity.update(delta, level, entities);

it calls the entity function directly and the player specific stuff doesnt happen, however if I call it like this:

((Player)entities.get(0)).update(delta, level, entities);

it does. I thought I understood the problem but I tried the following code

private static class Foo{
    public void print(){
        System.out.println("I AM FOO");
    }
}
private static class Bar extends Foo{
    public void print(){
        System.out.println("i am bar");
        super.print();
    }
}
public static void main(String[] args){
    ArrayList<Foo> foos = new ArrayList<Foo>();
    foos.add(new Foo());
    foos.add(new Bar());
    for(Foo leFoo: foos)
        leFoo.print();
}

and it actually calls the print function from Bar when the object is a bar. I’m kinda lost at this point.

  • 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-11T23:55:41+00:00Added an answer on June 11, 2026 at 11:55 pm

    Since you have multiple Level classes, you have to ensure that the Player.update() method signature references the correct one (in order to override successfully):

    public class Player {
    
      @Override
      public void update(int delta, game.level.Level level, ArrayList<Entity> entities) { ... }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two entities: @Entity public class File ....... @Id @GeneratedValue(strategy=GenerationType.AUTO) private int id;
I have an arraylist which has a class datastructure. public class empRec { public
To start I have two entities. User.java @Entity public class User { @Id private
Suppose I have ArrayList with following contents public void add() { obj.add(1); obj.add(123456789); obj.add(1.222);
I have this simple situation: @Entity public class Customer{ @ManyToMany(fetch=FetchType.EAGER) @Cascade(CascadeType.SAVE_UPDATE) private List<Product> products=new
At the moment inside the class I have ArrayList which the objects are stored
I have three entities: User , Team , and TeamInvite . Each User has
I have a class Class TextChunks extends Token { ArrayList<Token> arrt = new ArrayList<Token>();
I have a list of embedded entities: @Embedded private List<EmbeddedEntity> embedded = new ArrayList<EmbeddedEntity>();
I have ArrayList<ColorDrawable> colors = new ArrayList<ColorDrawable>(); for(int i = 0; i = intList.size();

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.