如何废弃一个 case class 的 companion object?

5

我注意到如果一个样例类被弃用,它的伴生对象并不会被弃用。

scala> @deprecated case class A(x: Int)
warning: there was one deprecation warning; re-run with -deprecation for details
defined class A

scala> A(0)
res0: A = A(0)

scala> new A(0)
warning: there was one deprecation warning; re-run with -deprecation for details
res1: A = A(0)

我希望在使用 A(0) 时,能像使用 new A(0) 一样得到警告。我需要显式定义对象的伴生对象并将其弃用吗?是否有更好的方法呢?
1个回答

2

我尝试了这个:@deprecated("foo","") case class A(x: Int); @deprecated("bar","") object A,但调用A(0)仍然没有产生过时警告。 - Kolmar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接