Type safety warnings (eclipse)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hcarlens
    New Member
    • Sep 2007
    • 4

    Type safety warnings (eclipse)

    hey guys,

    I'm doing a small project which does some basic encryption and decryption, but I'm very new to Java and Eclipse is showing safety warnings but I have no idea what they mean or how I fix them. Here is the part of the code that's causing the problem:

    Code:
    	String[] AlphArray = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
    	ArrayList<String> Alphabet = new ArrayList(Arrays.asList(AlphArray));
    These are the error messages:
    Type safety: The constructor ArrayList(Colle ction) belongs to the raw type ArrayList. References to generic type ArrayList<E> should be parameterized.
    Type safety: The expression of type ArrayList needs unchecked conversion to conform to ArrayList<Strin g>.

    Can you please give me some tips on how to solve these problems?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by hcarlens
    Code:
    ArrayList<String> Alphabet = new ArrayList(Arrays.asList(AlphArray));
    Change that line to:

    [code=java]
    ArrayList<Strin g> Alphabet = new ArrayList<Strin g>(Arrays.asLis t(AlphArray));
    [/code]

    Your version uses a copy constructor of the 'raw' ArrayList type while you want
    a List of Strings.

    kind regards,

    Jos

    Comment

    • hcarlens
      New Member
      • Sep 2007
      • 4

      #3
      Thanks a lot, it works now.

      Comment

      Working...