Skip to content

can't suppress / override synthetic companion .apply #9547

Closed
@scabug

Description

@scabug

I want a case class where the access to its constructors (including companion.apply) is private, or to not have the synthetic constructor created.

case class Foo private(x: Int)
object Foo {
  // apply not public
  def make(x: Int): Option[Foo] = ??? // public constructor
}

Adding or overriding Foo.apply causes "error: method apply is defined twice".

The only workaround I could find is to not use a case class; use a regular class, and define your own val, apply, unapply, toString, canEqual, equals, hashCode; seems unfortunate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions