Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Generic = does not conform to bounds of method

 
Gunslinger
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, so generics are killing me here. Sorry for all of the questions, but you don't know until you ask, right? Why do I get the following error if I clearly declare myList to be an array of Strings and bound the method with String?

<T>fillArray(T...) in Ch15.ArrayList<T> cannot be applied to (Ch15.ArrayList<java.lang.String>); inferred type argument(s) Ch15.ArrayList<java.lang.String> do not conform to bounds of type variable(s) T


 
Sheriff
Posts: 22509
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
fillArray expects any number of Strings, or a single String[]. You are passing an ArrayList<String>. That does not match, now does it?

Don't you mean Because that does compile (with a warning about the cast to T[]).
 
James Brooks
Gunslinger
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Prime wrote:fillArray expects any number of Strings, or a single String[]. You are passing an ArrayList<String>. That does not match, now does it?

Don't you mean Because that does compile (with a warning about the cast to T[]).



OK, so I wasn't passing it the instance variable list[] like I thought I was doing. I see that now, thank you!
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic