aspose file tools
The moose likes Java in General and the fly likes Warning error ..? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Warning error ..?" Watch "Warning error ..?" New topic
Author

Warning error ..?

santhosh.R gowda
Ranch Hand

Joined: Apr 06, 2009
Posts: 296
Dear all


In this code mapVendorRegions is an hashmap which consists of key as string and value as an arraylist object which holds only string the code is compiled with 2 warnings please let me know to clear warnings
im getting warning as follows:

PreferenceSetupController.java:699: warning: [unchecked] unchecked cast
found : java.lang.Object
required: java.util.Map.Entry<java.lang.String,java.util.ArrayList<java.lang.Str
ing>>
Map.Entry<String
,ArrayList<String>> mapRemainEntry= (Map.Entry<String,ArrayList<String>>)itx.nex
t();

Creativity is nothing but Breaking Rules
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14913
    
  26

Why are you using the raw type Set in this line:

Do this instead:

Then you also don't need the cast anymore in the line inside the loop:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
santhosh.R gowda
Ranch Hand

Joined: Apr 06, 2009
Posts: 296
Dear sir

As you told i had made changes in my code and compiled but still its giving me the same warning
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14913
    
  26

You need to add the generics to Iterator too.

But better is to not use an Iterator at all and use the Java 5 for-loop syntax:

Try to understand the warning - it says you are casting from Object to Map.Entry<String,ArrayList<String>> and the compiler warns you that it has no way to check if that cast is safe or not.
santhosh.R gowda
Ranch Hand

Joined: Apr 06, 2009
Posts: 296
Thanks sir i got with out warning
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 43303
    
  32
It is not the absence of warnings you should be worrying about. It is the absence of risks of a ClassCastException. If you compile with no warnings and no "suppress warnings" annotations, then you are not risking a ClassCastException.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Warning error ..?
 
It's not a secret anymore!