javagenericsinheritancecompiler-errorsname-clash

Java name clash error, a method has the same erasure as another method


I have two classes as follows

class QueryResult:

public class QueryResult
{
...
public static List sortResults(boolean ascending, List<QueryResult> toSort)
    {   ...
    }
}

and class CaseResult:

public class CaseResult extends QueryResult
{
...
public static List sortResults(boolean ascending, List<CaseResult> toSort)
    {   ...
    }
}

I am getting the following error:

Name clash: The method sortResults(boolean, List) of type CaseResult has the same erasure as sortResults(boolean, List) of type QueryResult but does not hide it CaseResult.java

I tried answers under the similar question Java generics name clash , has the same erasure but got more errors. I think I may misunderstand something or those answers do not fit my case.

Could someone please provide any solutions or explain more to help me understand? Thank you all.


Solution

  • As per Java Documentation,

    If a subclass defines a static method with the same signature as a static method in the superclass, then the method in the subclass hides the one in the superclass.

    The distinction between hiding a static method and overriding an instance method has important implications: