• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Conversion of Arrays to List - code causing compiler error

 
Sandra Bachan
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • 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.


 
Henry Wong
author
Marshal
Pie
Posts: 21515
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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


  •  
    Soumya Ranjan Mohanty
    Ranch Hand
    Posts: 44
    • Mark post as helpful
    • send pies
    • 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.
     
    Abimaran Kugathasan
    Ranch Hand
    Posts: 2066
    Clojure IntelliJ IDE Linux
    • Mark post as helpful
    • send pies
    • 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....
     
    Bert Bates
    author
    Sheriff
    Posts: 8900
    5
    • Mark post as helpful
    • send pies
    • 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
    • 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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic