1

I have a method with this signature:

   protected final Map<String, Object> buildOutputMappings(
                                 AbstractDataObject ado, MDBase md)

And called with this method (in a subclass):

   Map<String, Object> params = buildOutputMappings(ra, md);

I get this compiler warning:

      Warning:Warning:line (136)[unchecked] unchecked conversion
found   : java.util.Map
required: java.util.Map<java.lang.String,java.lang.Object>

Changing params to an ungenericized Map removes the compiler warning. Why is this and how can it be avoided (other than suppression)?

EDIT: This is JDK 1.5, and line 136 is the assignment statement above. Neither class is paramterized, they just have methods that return a Map of a generic type. The returned object within the method is also genericized.

EDIT: The superclass is indeed genericized, although return value has nothing to do with those generics. Here is the code of the method, although with the disclaimer that I didn't write this and I know it is ugly:

protected final Map<String, Object> buildOutputMappings(AbstractDataObject ado, MDBase md) throws DAOException {
  try {
     ....
     Map<String,Object> params = new HashMap<String, Object>(spc.getNumberInParams());
     ....
     return params;
  }
  catch (Exception e) {
     logger.undeterminedError(e);
     throw new DAOException(e.getMessage(), e);
  }
}

Here are the class declarations:

public abstract class DAOBase<T extends AbstractDataObject>

public class RoleAssignmentDAO extends DAOBase
Yishai
  • 90,445
  • 31
  • 189
  • 263
  • What version of Java are you using? – Paul Sonier Jun 24 '09 at 17:05
  • 1
    what is the line 136? is one of these two you showed? – cd1 Jun 24 '09 at 17:05
  • No warning here, tested with both Java 5 and Java 6 – dfa Jun 24 '09 at 17:08
  • 1
    Could you include your return code? I have a feeling it's your return that's causing you issues. – Joseph Jun 24 '09 at 17:08
  • 1
    there's something we don't know about your code. for what I can see, your code is fine. if you post your method's code here, it will help. – cd1 Jun 24 '09 at 18:19
  • is this like a puzzler challenge? we get the edit with a few more tidbits of information but not much else? general tip to question posters: the more information, the more likely someone will be able to help you! – james Jun 24 '09 at 19:09
  • @james, I was away from my office computer when I put in the first edit, so I didn't have the actual code in front of me to put in. – Yishai Jun 24 '09 at 19:23
  • @yishai, no problem, glad i could help. i was a little confused by the first edit. – james Jun 24 '09 at 19:26

2 Answers2

5

my guess is that you are not using generics correctly in the subclass, and the compiler is disabling generics for the class. thus the return type for the buildOutputMappings call is being converted to the raw type and the warning is being generated. is the parent class parameterized? does the subclass include types for the parent classes parameters?

In short, your error is most likely a dropped type parameter somewhere in the subclass or parent class.

james
  • 1,379
  • 7
  • 6
  • +1 for being right, and I wish I could give you another +1 for being psychic. – Michael Myers Jun 24 '09 at 19:16
  • This was the correct answer. The compiler removes generics from the super class given that the subclass doesn't use the parameter type. – Yishai Jun 24 '09 at 19:19
4

I have a feeling that your actual return statement is not matching your returning the correct type as indicated by your method definition. I can't be sure because you don't have the code included.

Joseph
  • 25,330
  • 8
  • 76
  • 125