• 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

Conversion of Arrays to List - code causing compiler error

 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Below is code from Chapter 7, Sierra/Bates



When I compile, with javac Conversion.java I get:

Conversion.java:6: cannot find symbol
symbol : variable Array
location: class Conversion
List sList = Array.asList(sa);
^
Note: Conversion.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error


When I recompile with javac -Xlint Conversion.java I get:

Conversion.java:6: cannot find symbol
symbol : variable Array
location: class Conversion
List sList = Array.asList(sa);
^
Conversion.java:10: warning: [unchecked] unchecked call to set(int,E) as a member of the raw type java.util.List
sList.set(2, "six");
^
1 error
1 warning



I pulled this code from the book, and imported the proper libraries (I think). Please guide.


 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I think you want the Arrays class -- and not the Array class.

Henry
 
Sandra Bachan
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:
I think you want the Arrays class -- and not the Array class.

Henry



I made the correction and still get this warning:

Note: Conversion.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.


  • What are they talking about because I haven't read about it in Sierra/Bates?
  • How do I fix this?
  • Nonetheless, my code runs and outputs as shown in the book


  •  
    Ranch Hand
    Posts: 44
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator



    I think now you won't get such warning. Now your list is Generic and type safe, It will only take String otherwise compilation error.
     
    Ranch Hand
    Posts: 2066
    IntelliJ IDE Clojure Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    If you are using version after JDK1.5, it will give those warnings. It's no a problem. Go ahead... And, if you generic types of object and methods, then, there won't be any warnings....
     
    author
    Posts: 9050
    21
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hey Sandra,

    Hang in there - you're a few pages away from a discussion of those pesky compiler warnings you're starting to experience
     
    Sandra Bachan
    Ranch Hand
    Posts: 434
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    @ Bert: Yes, I did come across the explanation for those compiler errors and it makes sense


    @ Soumya: Now I fixed the code and now the compiler is silent.
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic