Skip to content

Instrumentation methods should have more flexible generic return type #3609

Closed
@paulbakker

Description

@paulbakker

Describe the bug
Methods in Instrumentation currently return InstrumentationContext<Object>. This won't allow to return a more concrete object type. E.g. returning InstrumentationContext<String> does not compile.

I think these methods should return InstrumentationContext<?>.

To demonstrate this further, take this (plain Java) example:

interface Base {
    Wrapper<Object> wrapped();
}

class Wrapper<T> {
    T value;
}

class Impl implements Base {
    @Override
//Won't Compile!!!!!
    public Wrapper<String> wrapped() {
        return new Wrapper<String>();
    }
}

This won't compile, String is an incompatible return type here.
However, if you change from object to ?, it's fine.

interface Base {
    Wrapper<?> wrapped();
}

class Wrapper<T> {
    T value;
}

class Impl implements Base {
    @Override
    //Now it's fine.
    public Wrapper<String> wrapped() {
        return new Wrapper<String>();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions