Results 1 to 3 of 3
  1. #1
    peter_thm is offline Member
    Join Date
    Jan 2009
    Posts
    5
    Rep Power
    0

    Default function call error

    Hey, I am trying to call a function
    printTable(table); (where table is of type List<List<Double>>)

    The function declaration is
    public static void printTable(List<List<?>> c)

    Netbeans shows that there is something wrong and when I try to compile it gives the following error:
    printTable(java.util.List<java.util.List<?>>) in javaapplication1.TableIO cannot be applied to (java.util.List<java.util.List<java.lang.Double>>)
    printTable(table);

    I guess I might have used the wildcard incorrectly. Any ideas?
    Thanks

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    What do you really want to do? Why are you using java.util.List<java.util.List<?>> ?

    http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf

  3. #3
    peter_thm is offline Member
    Join Date
    Jan 2009
    Posts
    5
    Rep Power
    0

    Default

    Hey, thanks for the pdf, I've only been reading up on this and collections for 2 days and I've obviously missed some details.

    I checked the generic methods section and changed the function declaration to the following and it works now.
    public static <T> void printTable(List<List<T>> c)

    'table' is basically a (2d) table of values, in this case numbers. The function prints out the contents of the table in a way so it kind of looks like a table. I want to be able to use the function for tables of strings as well so I thought I should use a wildcard in the input parameter, which didn't end up working (although I'm still not sure why).

    Anyway thanks
    If you have anything to add, I'll still be here.

Similar Threads

  1. Does this function cause lag?
    By Addez in forum New To Java
    Replies: 5
    Last Post: 12-06-2009, 10:53 AM
  2. Replies: 3
    Last Post: 12-04-2009, 03:08 PM
  3. Rewrite as a function so it can call from main.
    By thangli in forum New To Java
    Replies: 2
    Last Post: 11-30-2008, 06:26 AM
  4. Replies: 0
    Last Post: 07-07-2008, 07:10 AM
  5. help with System.exit (1) function call
    By katie in forum Advanced Java
    Replies: 2
    Last Post: 08-06-2007, 08:03 PM

Posting Permissions

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