CrazyEngineers
  • This the ERROR in Java code during compilation .What is this??

    Updated: Oct 22, 2024
    Views: 974
    Note: ABC1.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.


    Now when i use :

    javac ABC1.java -Xlint

    ABC1.java:26: warning: [unchecked] unchecked call to add(E) as a member of
    the raw type java.util.ArrayList
    list1.add(p);
    ^
    1 warning
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • komputergeek

    MemberMar 26, 2009

    I guess you haven't used try-catch block to catch exception in your program.Please post your program.
    Are you sure? This action cannot be undone.
    Cancel
  • ms_cs

    MemberMar 26, 2009

    Post your full code here...It will be easy to debug..
    Are you sure? This action cannot be undone.
    Cancel
  • shalini_goel14

    MemberMar 27, 2009

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


    Now when i use :

    javac ABC1.java -Xlint

    ABC1.java:26: warning: [unchecked] unchecked call to add(E) as a member of
    the raw type java.util.ArrayList
    list1.add(p);
    ^
    1 warning
    This kind of warning you get when you use jdk1.5 to compile but not in actually using "Generics" feature of jdk1.5 properly or when you mix generic collections with non-generic collections and try to "add"(note not on retreive) something to the list that is not type-safe.

    See the sample program for this:
    package myjava;
    import java.util.*;
    /**
     *
     * @author shalinig
     */
    public class TestBadLegacy {
    public static void main(String args[]){
        List<Integer> myList = new ArrayList<Integer>();
        myList.add(4);
        myList.add(6);
        Inserter in =new Inserter();
        in.insert(myList);
    }
    }
    class Inserter{
        void insert(List list){ //you need to use generics here also
            list.add(new String("42"));
        }
    }
    
    So make insert method something like this:
    void insert(List<Integer> list) rather than void insert(List list)

    Hope this may be of any help 😀

    Thanks
    Are you sure? This action cannot be undone.
    Cancel
  • shalini_goel14

    MemberMar 30, 2009

    Hey Sahil , Is your problem solved? Please devote some time to share the whole problem with solution here? 😀

    Thanks
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register