*
The moose likes Java in General and the fly likes Question in Generic Methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Question in Generic Methods" Watch "Question in Generic Methods" New topic
Author

Question in Generic Methods

Pranav Pal
Ranch Hand

Joined: Nov 04, 2007
Posts: 74
I have following code:


Compiling the above code gives following error:
Test2.java:19: process(java.util.Map<java.lang.String,java.util.HashMap<java.lang.Long,? extends core.Fruit>>) in core.Test2 cannot be applied to (java.util.Map<java.lang.String,java.util.HashMap<java.lang.Long,core.Fruit>>)
process(buildingblocksmap);
^
1 error
Can anybody please explain the reason of this error?


Hakuna Matata!
Sai Hegde
security forum advocate
Ranch Hand

Joined: Oct 26, 2010
Posts: 199
    
    1

The process method signature needs to be changed to this.

Matt Cartwright
Ranch Hand

Joined: Aug 25, 2008
Posts: 149

Sai Hegde wrote:The process method signature needs to be changed to this.




got it wrong first, but yes that works....

Sai Hegde
security forum advocate
Ranch Hand

Joined: Oct 26, 2010
Posts: 199
    
    1

I think you are confusing the compiler here...

Try this -
Matt Cartwright
Ranch Hand

Joined: Aug 25, 2008
Posts: 149

Sai, you're right, the original method definition works alright
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Question in Generic Methods
 
Similar Threads
Make HashMap elements fit into an ArrayList
Giving error when compiling with ant but not showing the error in eclips
enum "initialization circularity"?
Problem in Creating HashMap object then display in sorted and unsorted order
Problem regarding HashMap.