Java generics parameters with base of the generic parameter

Posted by Iulian Serbanoiu on Stack Overflow See other posts from Stack Overflow or by Iulian Serbanoiu
Published on 2010-03-26T09:32:10Z Indexed on 2010/03/26 9:43 UTC
Read the original article Hit count: 531

Filed under:
|
|

Hello,

I am wondering if there's an elegant solution for doing this in Java (besides the obvious one - of declaring a different/explicit function. Here is the code:

private static HashMap<String, Integer> nameStringIndexMap 
        = new HashMap<String, Integer>();
private static HashMap<Buffer, Integer> nameBufferIndexMap 
        = new HashMap<Buffer, Integer>();

// and a function
private static String newName(Object object, 
        HashMap<Object, Integer> nameIndexMap){
    ....
}

The problem is that I cannot pass nameStringIndexMap or nameBufferIndexMap parameters to the function. I don't have an idea about a more elegant solution beside doing another function which explicitly wants a HashMap<String, Integer> or HashMap<Buffer, Integer> parameter.

My question is: Can this be made in a more elegant solution/using generics or something similar?

Thank you,

Iulian

© Stack Overflow or respective owner

Related posts about java

Related posts about generics