Solved

Type safety: Warnings Eclipse

Posted on 2011-03-24
5
1,363 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 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

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…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

687 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