Scala - Can implicitNotFound annotation be applied at the method level?

試著忘記壹切 提交于 2020-01-02 03:54:07

问题


I have a method that takes type parameters with an implicit view bounds on them. Can I use the @implicitNotFound annotation to give nicer compiler errors when the method is called with invalid data types?

The documentation for the method is useless and even the source code doesn't help, and all the examples of use online are at the trait or class level.


回答1:


No, you cannot directly do that. As you’ve noticed, @implicitNotFound annotates traits or classes. You could, however, make a special implicit type just for that method and annotate it if you really wanted to have a custom message.



来源:https://stackoverflow.com/questions/13840115/scala-can-implicitnotfound-annotation-be-applied-at-the-method-level

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