• 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

having problems getting into java5

 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i tried this code:

i get a compiler error saying reference needed int provided
i changed to the old school way:


now i just get the warning that i am using unsafe operation.
i thought java5 made it so we didn't need wrappers??
i am also new to ArrayList, (i choose arrays if possible), any help appreciated.
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nope sorry Randall. Generics don't work with primitive types. If you want to store integers in a list, you will need a List<Integer>. List<int> won't work. However, you can still add regular ints to a List<Integer>, because Java 5 provides autoboxing: The compiler will automatically convert between wrapper types and primitives where appropriate.
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, i think i understand. i have to declare it using <Integer> but i can add int's to it directly due to the autoboxing feature.
 
Sheriff
Posts: 22783
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
One thing - shouldn't you increase index inside your loop? Right now, your list will contain 0, 1 and then 39999998 times 1.
 
reply
    Bookmark Topic Watch Topic
  • New Topic