1

In the Scala standard library there is a class Proxy[T]. From the API:

This class implements a simple proxy that forwards all calls to the public, non-final methods defined in class Any to another object self.

From the above, and numerous Q&A in stack overflow regarding this class, I would infer that this is the same as using an implicit class.

Is this correct? If so, what are the advantages/disadvantages of using the Proxy class over the implicit keyword?

Luciano
  • 2,388
  • 1
  • 22
  • 33

1 Answers1

2

These two things are entirely unrelated. The description of Proxy is a bit misleading. All it does is implemented hashCode, equals and toString in terms of the peer object. It doesn't have magic power to forward any other methods.

See also this question: How do I use the trait scala.Proxy

0__
  • 66,707
  • 21
  • 171
  • 266
  • Referring to the related question, the accepted answer suggests using `Proxy` to extend another class with new methods. You could achieve the same with code `implicit class RichFoo(self: Foo) { def newMethod = "do something cool" }`. Isn't this the same thing in practice? – Luciano Nov 07 '15 at 18:23
  • 1
    Frankly, I don't know why you would ever want to use `Proxy`. Certainly I have never done it… – 0__ Nov 07 '15 at 18:26