0

Reading a Java project on GitHub, I found a code syntax that I have never seen before and I would some explanation, please. Here is the code:

Book book = new BookBuilder() {
    {
        description("blabla");
        author("blabla");
        title("blabla");
        isbn("123456789");
        category(category);
    }
}.build();

BookBuilder seems to be a standard java class and each of methods called (description, author...) return a BookBuilder object.
My question is, what does the syntax book = new BookBuilder() {{ ... }} means?

Andrew Tobilko
  • 46,063
  • 13
  • 87
  • 137
gWombat
  • 497
  • 2
  • 11

0 Answers0