List<String> Problem!

Discussion in 'Plugin Development' started by TheCanadianLizard, Feb 4, 2013.

Thread Status:
Not open for further replies.
  1. Hello, i have been developing my first plugin, and i come across this error while trying to do something. Here is my source code for the troublesome part:

    Code:
        public void EntityPortal(EntityPortalEvent event) {
            List<String> pfm = plugin.getConfig().getStringList("blocked-mobs");
            if (pfm.contains(event.getEntityType().toString())) {
                event.setCancelled(true);
                System.out.println("The Mob " + event.getEntityType().toString() + " Has Tried To Use A Portal!");
            }
        
    Aaaaaand it gives me this error on the List part:

    How can i go about fixing this?
     
  2. Offline

    bitWolfy

    Well, which List are you importing? If it's java.awt.list, then it's not parameterized. You need java.util.list.
     
  3. Offline

    ohtwo

    Try:
    ArrayList<String> pfm = plugin.getConfig().getStringList("blocked-mobs");

    I don't know exactly why, but I think List may just be an abstract class or something along those lines. You need a class that implements List such as ArrayList.

    EDIT: It would be nice for someone to correct me on that.
     
  4. Offline

    desht

    Alright then :)

    List is an interface, and it's perfectly OK to say "List<String> list = something-or-other"

    Good programming practice is to program to interfaces rather than concrete classes, so it's better to make your data types interface types where possible. You use the concrete class (such as ArrayList) to instantiate your objects, e.g.:
    Code:
    List<String> list = new ArrayList<String>();
    
    http://stackoverflow.com/questions/383947/what-does-it-mean-to-program-to-an-interface

    Oh, and I'm guessing bitWolfy has the right solution - TheCanadianLizard check which List class you're actually importing.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
    ohtwo likes this.
  5. Thanks Wolf, apparently i did import java.awt.list XD
     
Thread Status:
Not open for further replies.

Share This Page