?
Solved

Type safety: Warnings Eclipse

Posted on 2011-03-24
5
Medium Priority
?
1,387 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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 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…
Suggested Courses
Course of the Month12 days, 23 hours left to enroll

777 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