简体   繁体   中英

Type mismatch: cannot convert from element type Object to EnderPearl

Okay so, I have a problem... The title basically explains the error. But I have no idea on how to fix it. So would be glad if you could help me.

          if (cause == PlayerTeleportEvent.TeleportCause.ENDER_PEARL)
      {
        ArrayList pearls = (ArrayList)this.ender.get(e.getPlayer());

          if (pearls != null)
          {
              Location to = e.getTo();
              for (EnderPearl p : pearls) //**Error is here. ("pearls")**
              {
                  if ((p != null) && (p.getLocation().distanceSquared(to) < 2.0D))
                  {
                      pearls.remove(p);
                      e.setCancelled(true);
                      return;
                      }
                  }
              }
          }

In your code you use raw types where you you would be better off using the following code to define your array list:

ArrayList<EnderPearl> pearls = (ArrayList)this.ender.get(e.getPlayer());

And then you don't have to worry about casting or anything!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM