java - How can I create a generic method signature for "any map entry" value in the parameter list and/or return type? -


in code i'm refactoring, there exists similar operation on bunch of maps. maps of following type:

map<<sometype>,double> mymap;  

they undergo same transformation , converted to:

treemap<integer, <sometype>> transformedmap; 

i wanted know if it's possible create generic method looks this:

public treemap<integer, <t>> transformmap(map<<t>,double> mymap){...} 

what's way accomplish this? sometype kind of object/collection. replace <t> object wanted know if there better solution. above method signature, doesn't work :)

sometypes created system , operated upon in code. can't make changes source.

you close generic method solution. define generic type parameter <t>, use without own <> in return type , parameter type.

public <t> treemap<integer, t> transformmap(map<t, double> mymap) {...} 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -