java - What is "Type mismatch" and how do I fix it? -


how fix error?

type mismatch: cannot convert element type object block

i see @ line:

for (block b : blockstoskip){ 

here full code.

@eventhandler(priority=eventpriority.normal, ignorecancelled=true) public void onentityexplode(entityexplodeevent ev){     arraylist blockstoskip = new arraylist();     location rootloc = ev.getlocation();     if (!skymagic.isinislandworld(rootloc)) return;     (block b : ev.blocklist()){         location loc = b.getlocation();         islanddata data = skymagic.getislandat(loc);         if ((data != null) && (data.owner != null)){             blockstoskip.add(b);         }     }     (block b : blockstoskip){         ev.blocklist().remove(b);     } } 

this raw type:

arraylist blockstoskip 

java expects everything, not block type. therefore, need type cast.

arraylist blockstoskip = new arraylist();  // rest of code  (object b : blockstoskip){     ev.blocklist().remove( (block)b ); } 

note discouraged use raw types. should parameterize instead.

arraylist<block> blockstoskip = new arraylist<block>(); 

Comments

Popular posts from this blog

javascript - ScrollTo Effect (href to div) -

javascript - ng-class not responding to change in model in Angular? -

javascript - document.registerElement extending HTMLInputElement prototype while using custom tag name to avoid implicit browser style -