Skip to content

default no-args constructor should be generated for classes with all-optional arguments #4278

Closed
@scabug

Description

@scabug

= problem =

For a lot of java libraries or frameworks, a default no-args constructor for a class is required. Some examples:

  • RPC
  • Serialization
  • Servlets

If you have a class with only optional arguments (like class A(i : Int = 0)), you'd expect it would work in such a situation.

There is also no easy way to access default values for constructors from java.

= analysis =

There is really no idiomatic way to create classes that adhere to such an interface in scala, see: http://stackoverflow.com/questions/4045863/scala-extra-no-arg-constructor-plus-default-constructor-parameters

It is not a very common use case, but it would improve java-scala interop by fixing this.

= enhancement recommendation =

There are two ways to fix this:

  • Generate a default constructor by default for every class where each constructor parameter is optional
  • If the overhead for such a solution is unacceptable, then a annotation marking which classes should get a default constructor could be used

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions