Skip to content

[java] LooseCoupling false-positive with methods only available on concrete collection class #1218

@boris-petrov

Description

@boris-petrov

Not exactly sure if this is a false-positive, but it is strange.

private final LinkedList<String> list = new LinkedList<>();
...
Iterator<String> descendingIterator = list.descendingIterator();
String value = list.getLast();

Technically, the rule is correct. However, the List interface doesn't have descendingIterator, neither does it have getLast and some other useful methods. I guess that when such methods are used, this warning should be disabled? Or do you think that this is bad design nonetheless and people should try to use other methods that are in the interface to simulate those (that certainly is possible, however more inconvenient)? I'm interested on more opinions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions