Results 1 to 3 of 3
Thread: function call error
- 01-13-2010, 08:58 AM #1
Member
- Join Date
- Jan 2009
- Posts
- 5
- Rep Power
- 0
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
- 01-13-2010, 09:14 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
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
- 01-13-2010, 12:57 PM #3
Member
- Join Date
- Jan 2009
- Posts
- 5
- Rep Power
- 0
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
-
Does this function cause lag?
By Addez in forum New To JavaReplies: 5Last Post: 12-06-2009, 10:53 AM -
Possible? Callback function passed as arguments to another function
By TreyAU21 in forum Advanced JavaReplies: 3Last Post: 12-04-2009, 03:08 PM -
Rewrite as a function so it can call from main.
By thangli in forum New To JavaReplies: 2Last Post: 11-30-2008, 06:26 AM -
Error using ajax call in onchange event of select box.... struts 1.x?
By prabhurangan in forum Web FrameworksReplies: 0Last Post: 07-07-2008, 07:10 AM -
help with System.exit (1) function call
By katie in forum Advanced JavaReplies: 2Last Post: 08-06-2007, 08:03 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks