0

I came across a piece of code as follows:

  final static Map<String, Supplier<Shape>> map = new HashMap<>();
  map.put("CIRCLE", Circle::new);

Where Circle is a class. I guess here new is used to access the constructor of the class Circle. How can new be used like this? What is this technique called? I could not find any documentation.

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
Athul T R
  • 47
  • 1
  • 6
  • It's sintactic sugar, see if the answers to [this question](https://stackoverflow.com/questions/20001427/double-colon-operator-in-java-8) help. – JustAnotherDeveloper Aug 19 '20 at 08:10
  • 2
    Does this answer your question? [New object instantiation when using Java 8 streams](https://stackoverflow.com/questions/31763930/new-object-instantiation-when-using-java-8-streams) – Dokksen Aug 19 '20 at 08:12

1 Answers1

0

This a reference to a constructor. You can pass that where a matching functional interface is expected. Look here for more info http://tutorials.jenkov.com/java/lambda-expressions.html#constructor-references

Renato
  • 71
  • 5