Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deprecate the companion object of a case class?

I noticed that if a case class is deprecated its companion object is not.

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)

I would like to get a warning for A(0) exactly as I get it for new A(0). Should I define the companion object explicitly and deprecate it ? Is there any better way ?

like image 547
Michael Avatar asked Oct 30 '22 01:10

Michael


1 Answers

Should I define the companion object explicitly and deprecate it ?

Apparently so! According to https://issues.scala-lang.org/browse/SI-2799, it should be deprecated automatically (and it makes sense to me), but it doesn't seem to be anymore.

like image 156
Alexey Romanov Avatar answered Nov 15 '22 07:11

Alexey Romanov