How to extend Collectors class

Prasath :

Why Collectors class is final in Java 8? I want to extend Collectors class in my own class MyCollectors. There I will add additional methods which is not existing available in Collectors class.

Eran :

Collectors is final because it only contains static utility methods. It cannot be instantiated (its constructor is private), and therefore there would be no meaning to sub-classing it.

You can create your own MyCollectors class independent of Collectors. Or if you want to access Collectors methods via your MyCollectors, you can create wrappers of all the Collectors static methods within your MyCollectors class.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=114226&siteId=1