title: Java's Interface and Haskell's type class: differences and similarities?
body: <p>While I am learning Haskell, I noticed its <strong>type class</strong>, which is supposed to be a great invention that originated from Haskell.</p>
  
  <p>However, in <a href="http://en.wikipedia.org/wiki/Type_class">the Wikipedia page on type class</a>:</p>
  
  <blockquote>
    <p>The programmer defines a type class by specifying a set of function or
    constant names, together with their respective types, that must exist
    for every type that belongs to the class.</p>
  </blockquote>
  
  <p>Which seems rather close to <strong>Java's Interface</strong> to me (quoting <a href="http://en.wikipedia.org/wiki/Interface_%28Java%29">Wikipedia's Interface(Java) page</a>):</p>
  
  <blockquote>
    <p>An interface in the Java programming language is an abstract type that
    is used to specify an interface (in the generic sense of the term)
    that classes must implement.</p>
  </blockquote>
  
  <p>These two looks rather similar: type class limit a type's behavior, while interface limit a class' behavior.</p>
  
  <p>I wonder what are the differences and similarities between type class in Haskell and interface in Java, or maybe they are fundamentally different?</p>
  
  <p><strong>EDIT:</strong> I noticed <a href="http://www.haskell.org/haskellwiki/OOP_vs_type_classes#Type_classes_are_like_interfaces.2Fabstract_classes.2C_not_classes_itself">even haskell.org admits that they are similar</a>. If they are so similar (or are they?), then why type class is treated with such hype?</p>
  
  <p><strong>MORE EDIT:</strong> Wow, so many great answers! I guess I'll have to let the community decide which is the best one. However, while reading the answers, all of them seem to just say that <em>"there are many things typeclass can do while interface cannot or have to cope with generics"</em>. I cannot help but wondering, are there anything <strong>interfaces can do while typeclasses cannot?</strong> Also, I noticed that Wikipedia claims that typeclass was originally invented in the 1989 paper *"How to make ad-hoc polymorphism less ad hoc", while Haskell is still in its cradle, while Java project was started in 1991 and first released in 1995. So <strong>maybe instead of typeclass being similar to interfaces, its the other way around, that interfaces were influenced by typeclass?</strong> Are there any documents/papers support or disprove this? Thanks for all the answers, they are all very enlightening!</p>
  
  <p>Thanks for all the inputs!</p>