Solved

Type safety: Warnings Eclipse

Posted on 2011-03-24
5
1,343 Views
Last Modified: 2012-05-11
I have 3 warnings in my code

  public SortingListModel()
    {
         model = new TreeSet( USEFUL_COMPARATOR ); <= warning here
    }

Open in new window

warning = Type safety: The method addElement(comparator) belongs to the raw type
Vector. References to generic type Vector<E> should be parameterized

    public void addElement( Object element )
    {
        
        if( model.add( element ))<= warning here
        {
            fireContentsChanged( this, 0, getSize() );
        }
    }

Open in new window

warning = Type safety: The method addElement(object) belongs to the raw type
Vector. References to generic type Vector<E> should be parameterized

Collection c = Arrays.asList(elements);
        model.addAll(c); <= warning here
        fireContentsChanged( this, 0, getSize() );

Open in new window

Warning = warning = Type safety: The method addElement(collection) belongs to the raw type
Vector. References to generic type Vector<E> should be parameterized

I am not sure how to address these warnings
0
Comment
Question by:jkteater
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 35210134
You can ignore them for the moment
0
 

Author Comment

by:jkteater
ID: 35210171
I wish I could :)  but I have been asked to remove all the warnings from our project.  There are a few more of those warnings than posted above.  I have read up on the error, but I not sure how to fix them
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35210213

You certainly can ignore those.
If you want to learn more about these types of warnings,  here are some explanations:
http://www.angelikalanger.com/GenericsFAQ/FAQSections/ParameterizedTypes.html#FAQ201

If you read the whole FAQ, you'll probably know everything about it:
http://www.angelikalanger.com/GenericsFAQ/FAQSections/ParameterizedTypes.html

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35210216
The proper way to remove them is to genericise all collection classes. Other ways you could do it:

a. pass the -nowarn flag to the compiler
b. set the vm to a version < 5
c. annotate all methods

(The last one is a very bad way of doing it ;))
0
 
LVL 92

Accepted Solution

by:
objects earned 125 total points
ID: 35212338
following assumes your list holds strings

>          model = new TreeSet( USEFUL_COMPARATOR ); <= warning here


should be:


         model = new TreeSet<String>( USEFUL_COMPARATOR ); <= warning here

(what do you need a Comparator for?)
And why use a set when its actually a list?

Also change the definition of model to:

Set<String> model;

>         if( model.add( element ))<= warning here

change that to:


        if( model.add( element.toString() ))<= warning here

> Collection c = Arrays.asList(elements);

Where is the array coming from?
That line should become:

   Collection<String> c = Arrays.asList(elements);
   
>         model.addAll(c); <= warning here

Above changes should fix that
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
varialbe initialization 11 32
hibernate insert example 13 28
hibernate example using maven 12 41
Convert from a json string array to a Java object 3 28
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to implement Singleton Design Pattern in Java.

806 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question