Java Enum definition

后端 未结 7 672
孤独总比滥情好
孤独总比滥情好 2020-11-22 17:24

I thought I understood Java generics pretty well, but then I came across the following in java.lang.Enum:

class Enum>
         


        
7条回答
  •  孤街浪徒
    2020-11-22 17:54

    This post has totally clarified to me these problem of 'recursive generic types'. I just wanted to add another case where this particular structure is necessary.

    Suppose you have generic nodes in a generic graph:

    public abstract class Node>
    {
        public void addNeighbor(T);
    
        public void addNeighbors(Collection nodes);
    
        public Collection getNeighbor();
    }
    

    Then you can have graphs of specialized types:

    public class City extends Node
    {
        public void addNeighbor(City){...}
    
        public void addNeighbors(Collection nodes){...}
    
        public Collection getNeighbor(){...}
    }
    

提交回复
热议问题