A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/2102 below:

[java] False positive MissingStaticMethodInNonInstantiatableClass when inheritors are instantiable · Issue #2102 · pmd/pmd · GitHub

Affects PMD Version: 6.19.0

Rule: MissingStaticMethodInNonInstantiatableClass

Description: if a class has only private constructors, it still may contain inner static inheritors. It is useful when implementing an ADT.

Code Sample demonstrating the issue:

public abstract class MyADT {
    private MyADT() {
    }

    public abstract <R> R map(
            Function<String, ? extends R> onString,
            Function<Integer, ? extends R> onInt
    );

    public static final class StringHolder extends MyADT {
        private final String string;

        public StringHolder(String string) {
            this.string = string;
        }

        @Override
        public <R> R map(Function<String, ? extends R> onString, Function<Integer, ? extends R> onInt) {
            return onString.apply(string);
        }
    }

    public static final class IntHolder extends MyADT {
        private final Integer integer;

        public IntHolder(Integer integer) {
            this.integer = integer;
        }

        @Override
        public <R> R map(Function<String, ? extends R> onString, Function<Integer, ? extends R> onInt) {
            return onInt.apply(integer);
        }
    }
}

Running PMD through: Gradle


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4