Skip to content

Parametrized methods where type parameter is used only in return type should be removed #1846

Open
@leventov

Description

@leventov

Typical example:

public interface CtNamedElement extends CtElement {
	<T extends CtNamedElement> T setSimpleName(String simpleName);
}

Type parameter T is used only in method's return type, not in the parameters.

It doesn't make sense in Java. If this method is defined in the interface (like CtNamedElement), it should just be declared to return CtNamedElement. Implementations in overriding classes narrow the return type to their actual type.

Why this is bad: it contaminates API usage from Kotlin, because type parameter couldn't be derived automatically and should always be specified.

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