Explain the syntax of Collections.emptyList()

后端 未结 5 1860
故里飘歌
故里飘歌 2020-12-24 01:35

I just studied about generic programming, the List interface, and ArrayList, so I can understand the statement below.

Arra         


        
5条回答
  •  滥情空心
    2020-12-24 02:23

    In a nutshell, this creates an empty, immutable list of strings.

    Let's look at the expression bit by bit.

    Collections is the name of a class. From the Javadoc:

    This class consists exclusively of static methods that operate on or return collections. It contains polymorphic algorithms that operate on collections, "wrappers", which return a new collection backed by a specified collection, and a few other odds and ends.

    emptyList() is the name of a static method defined in the Collections class (Javadoc). It is a generic method, and the in Collections.emptyList() specifies the generic type argument.

    The method returns a List, which in this case is List: a list of strings. More specifically, it returns an empty, immutable list of strings.

提交回复
热议问题