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();
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eb4603-69c3f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eb4603-69c3f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?