Scala - 可以在方法级别应用implicitNotFound 注释吗? [英] Scala - Can implicitNotFound annotation be applied at the method level?

查看:29
本文介绍了Scala - 可以在方法级别应用implicitNotFound 注释吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个方法,它接受类型参数,并在它们上面有一个隐式的视图边界.当使用无效数据类型调用该方法时,我可以使用 @implicitNotFound 批注给出更好的编译器错误吗?

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?

该方法的文档无用,甚至源代码也无济于事,在线使用的所有示例都在 trait 或 class 级别.

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.

推荐答案

不,你不能直接这样做.正如您所注意到的,@implicitNotFound 注释特征或类.但是,如果您真的想要自定义消息,您可以为该方法创建一个特殊的隐式类型并对其进行注释.

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.

这篇关于Scala - 可以在方法级别应用implicitNotFound 注释吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆