Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Error Code Mentioned in Session  RSS feed

 
Nishan Patel
Ranch Hand
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am doing the same course and also I was creating example given in the session. But I dont know why below code giving me error,



But line No 12 in code giving me ERROR "type mismatch; found : x.type (with underlying type T) required: T"

 
Maxim Karvonen
Ranch Hand
Posts: 121
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are defining your merge function as a generic function. So type T inside it references to "merge.T" type. But function lt regures "msort.T" type as its arguments.

To make it more clear, you code is completely equivalent to:

Do you see a problem now? lt requires T type but got M type. To fix a problem you can make merge function non-generic. It should have signature like

In this case T will reference to a type T defined as a parameter for msort.

Another solution is to keep merge function generic and pass comparator (lt) around all calls to it. But this solution is not so elegant as the first one.
 
Nishan Patel
Ranch Hand
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know why Still it is not working..
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!