我注意到如果一个样例类被弃用,它的伴生对象并不会被弃用。
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)
一样得到警告。我需要显式定义对象的伴生对象并将其弃用吗?是否有更好的方法呢?
@deprecated("foo","") case class A(x: Int); @deprecated("bar","") object A
,但调用A(0)
仍然没有产生过时警告。 - Kolmar