Skip to content

AbstractContextBuilder.set(Class<T>, T) implementation is weird #112

Description

@marschall

I had a look at the implementation of AbstractContextBuilder.set(Class, T) and I'm a bit confused:

    public <T> B set(Class<T> key, T value) {
        B old = set(key.getName(), Objects.requireNonNull(value));
        if (old != null && old.getClass().isAssignableFrom(value.getClass())) {
            return old;
        }
        return (B) this;
    }

It calls #set(String, Object), however this method does not return the old value but this so "old" is a confusing name. Then it makes tests whether "old" (which is this) is a super type of the value class. If it is it returns "old", which is this, otherwise it returns this.

I believe the method should just be:

    public <T> B set(Class<T> key, T value) {
        return set(key.getName(), Objects.requireNonNull(value));
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions