Why is proxying deprecated?

試著忘記壹切 提交于 2019-12-01 09:19:53

问题


This question about how to extend a Scala collection led me to this answer, which extends from SetProxy rather than Set. But SetProxy has since been deprecated! The documentation says "(Since version 2.11.0) Proxying is deprecated due to lack of use and compiler-level support."

Why has proxying not gotten use and compiler support? Does Scala provide a better technique for accomplishing the same thing? Was it found to have some fatal flaw?


回答1:


Proxying is deprecated because it is fragile. A proxy is supposed to forward all calls back to some other implementation. But what if you add a new method to the Set hierarchy--will anyone remember to add it to SetProxy and make sure it points where it should?

In practice, there was no good way to verify that proxies were actually functioning correctly. So the decision was made that it's better to not have the functionality at all than to have something that looks like it works but actually doesn't any more. Compiler support for proxying might make it easy enough to maintain robust proxies, but the manual approach just isn't robust enough.



来源:https://stackoverflow.com/questions/24312563/why-is-proxying-deprecated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!