[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Type safety: Warnings Eclipse

Posted on 2011-03-24
5
Medium Priority
?
1,399 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

656 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