java - Entity cannot be converted to ArrayList<Entity> -


i want read out first element of arraylist. problem when construct return method error saying 'entity cannot converted arraylist'. return function needs public arraylist, because i'm using foreach return values. can tell me i'm doing wrong , can improve this?

entity manager (public arraylist) doesn't work.

public class entitymanager {  private handler handler; private player player; private arraylist<entity> entities; private int counter = 0;   private comparator<entity> renderorder = new comparator<entity>(){         @override         public int compare(entity a, entity b) {                 if(a.gety() + a.getheight() < b.gety() + b.getheight())                         return -1;                 return 1;         } };  public entitymanager(handler handler, player player){     this.handler = handler;     this.player = player;     entities = new arraylist<entity>();     addentity(player); }  public void tick(){    iterator<entity> = entities.iterator();     while(it.hasnext()){         entity e = it.next();         e.tick();         if(!e.isactief()){             it.remove();             counter();             if(counter > entities.size() + 1){                player.eindspel = true;              }         }     }     entities.sort(renderorder); }  public void render(graphics g){     for(entity e : entities){         e.render(g);     }     player.postrender(g); } public arraylist<entity> getentities() {     return entities.get(0); } public void counter(){     counter++; } public void addentity(entity e){     entities.add(e); }  public void sethandler(handler handler) {     this.handler = handler; }  public void setplayer(player player) {     this.player = player; }  public void setentities(arraylist<entity> entities) {     this.entities = entities; }  public handler gethandler() {     return handler; } public player getplayer() {     return player;  } } 

the foreach i'm using read out values getentities

        for(entity e : handler.getwereld().getentitymanager().getentities()){         if(e.equals(this)){             continue;         }         if(e.getcollisionbounds(0, 0).intersects(ar)){             if(opslag.delete()){                 e.delete(2);                                 }         }     } 

the outcome want when e intersects want delete entity 'return entities.get(0)', first entity of entities arraylist. method won't work , when use 'return entities' of entites deleted, instead of first one.

if generalize external interface use list instead of arraylist (see here why that's idea), use collections.singletonlist construct list containing first entity.

however, seems pretty unintuitive me have method called getentities returns 1 entity. still don't when want entities, , when one. maybe can edit question explain use case little more


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -