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

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -