Solved

Type safety: Warnings Eclipse

Posted on 2011-03-24
5
1,322 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
Comment Utility
You can ignore them for the moment
0
 

Author Comment

by:jkteater
Comment Utility
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
Comment Utility

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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now