开发者

In Scala, is it possible to simultaneously extend a library and have a default conversion?

For example in the following article

http://www.artima.com/weblogs/viewpost.jsp?thread=179766

Two separate examples are given:

  1. Automatic string conversion
  2. Addition of append method

Suppose I want to have automatic string conversion AND a new append method. Is this possible? I have been 开发者_Python百科trying to do both at the same time but I get compile errors. Does that mean the two implicits are conflicting?


You can have any number of implicit conversions from a class provided that each one can be unambiguously determined depending on usage. So the array to string and array to rich-array-class-containing-append is fine since String doesn't have an append method. But you can't convert to StringBuffer which has append methods which would interfere with your rich array append.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜