How does the implementation class implement when the interface in Java returns List < own type >?

< H2 > scene: < / H2 >

this is the interface

public interface TreeNode<T> {
    public List<T> levelOrder();
    
    public List<TreeNode<T>> getChildNodes();
    
    public T getVal();
    
    public void setVal(T val);
}

this is the implementation class

public class BinaryTreeNode<T> implements TreeNode<T> {
    @Override
    public List<BinaryTreeNode<T>> getChildNodes(){
        return null;
    }
}

there will be an error here,

clipboard.png

if you change the return type to TreeNode < T > [], the implementation method can be BinaryTreeNode < T > [].

< H2 > question: < / H2 >

what should I do if I want the interface to return collection classes such as List/Map instead of arrays?

Jul.12,2022

 public List<? extends TreeNode<T>> getChildNodes();
Menu