Skip to content

Question: Handling Optional Parameters & Named Arguments with Subclasses #744

@EotT123

Description

@EotT123

When using optional parameters and named arguments in a class hierarchy, is there a way to avoid duplicating default values in subclasses?

class A {
    A(int foo = 2, String bar = "bar"){ ... }
}

class B extends A {
    B(int foo = 2, String bar ="bar", long fooBar = 5L){
        super(foo, bar);
        ...
    }
}

In this example, the default values for foo and bar must be repeated in both class A and B.

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