• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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: 22781
131
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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic