aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Conversion of Arrays to List - code causing compiler error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Conversion of Arrays to List - code causing compiler error" Watch "Conversion of Arrays to List - code causing compiler error" New topic
Author

Conversion of Arrays to List - code causing compiler error

Sandra Bachan
Ranch Hand

Joined: Feb 18, 2010
Posts: 434
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.



Marriage Made in Heaven
http://www.youtube.com/user/RohitWaliaWedsSonia
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18715
    
  40


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

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Sandra Bachan
Ranch Hand

Joined: Feb 18, 2010
Posts: 434
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

    Joined: Mar 07, 2010
    Posts: 44



    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

    Joined: Nov 04, 2009
    Posts: 2066

    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....


    |BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
    Bert Bates
    author
    Sheriff

    Joined: Oct 14, 2002
    Posts: 8813
        
        5
    Hey Sandra,

    Hang in there - you're a few pages away from a discussion of those pesky compiler warnings you're starting to experience


    Spot false dilemmas now, ask me how!
    (If you're not on the edge, you're taking up too much room.)
    Sandra Bachan
    Ranch Hand

    Joined: Feb 18, 2010
    Posts: 434
    @ 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.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Conversion of Arrays to List - code causing compiler error