Results 1 to 2 of 2

Thread: mismatcherror

  1. #1
    raykoo is offline Member
    Join Date
    Feb 2011
    Posts
    1
    Rep Power
    0

    Default mismatcherror

    public class Tester
    {

    public static void main(String[]args)
    {

    ArrayList<BankAccount> balance = new ArrayList<BankAccount>();


    balance.add(new BankAccount(1000));
    balance.add(new BankAccount(1500));
    balance.add(new BankAccount(750));
    balance.add(new BankAccount(2350));
    balance.add(new BankAccount(525));

    Collections.sort(balance); // this is the error line
    }



    public interface Comparable <BankAccount>
    {

    int compareTo(Object other);

    }


    public class BankAccount implements Comparable <BankAccount>
    {
    ..... etc
    }

    Can anyone tell me what my error is?

    Description
    Bound mismatch: The generic method sort(List<T>) of type Collections is not applicable for the arguments (ArrayList<BankAccount>). The inferred type BankAccount is not a valid substitute for the bounded parameter <T extends Comparable<? super T>>line 44 Java Problem

    Thanks.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,807
    Rep Power
    10

    Default

    Why have you written your own COmparable interface? Get rid of it and use the one in the Java API.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •