title: Java method referance complains about class not being functional interface
body: <p>I have got two cases of method referance:</p>
  <p>Case 1:</p>
  <pre><code>public class Main {
  
      static List&lt;Person&gt; personList = List.of(
              new Person(&quot;Daria&quot;, 27, List.of(new Book(&quot;Potop&quot;, &quot;H. Sienkiewicz&quot;),
                      new Book(&quot;Dywizjon 303&quot;, &quot;A. Fiedler&quot;))),
              new Person(&quot;Ola&quot;, 34, List.of(new Book(&quot;Czysty kod&quot;, &quot;R.C. Martin&quot;),
                      new Book(&quot;Hobbit&quot;, &quot;J. R. R. Tolkien&quot;))),
              new Person(&quot;Ala&quot;, 53, List.of(new Book(&quot;Potop&quot;, &quot;H. Sienkiewicz&quot;),
                      new Book(&quot;Wladca pierscieni&quot;, &quot;J. R. R. Tolkien&quot;))),
              new Person(&quot;Julka&quot;, 12, List.of(new Book(&quot;Dywizjon 303&quot;, &quot;A. Fiedler&quot;),
                      new Book(&quot;Hobbit&quot;, &quot;J. R. R. Tolkien&quot;))),
              new Person(&quot;Zuzia&quot;, 7, List.of(new Book(&quot;Robinson Crusoe&quot;, &quot;D. Defoe&quot;),
                      new Book(&quot;Alicja w krainie czarow&quot;, &quot;L. Carroll&quot;)))
      );
  
      public static void main(String[] args) {
          streamWithFunction_map();
      }
  
      public static void streamWithFunction_map(){
  
          // map() - let you convert object to sth else
          // List&lt;String&gt; to uppercase
          List&lt;String&gt; namesInCapitalList = personList.stream().map(person -&gt; person.getName().toUpperCase()).collect(Collectors.toList());
          namesInCapitalList.forEach(System.out::println); //DARIA OLA ALA JULKA ZUZIA
  
          // list of objects to list of Integers
          List&lt;Integer&gt; ageList = personList.stream().map(Person::getAge).collect(Collectors.toList());
          ageList.forEach(System.out::println); // 27 34 53 12 7
  
          // list of object A to list of object b
          List&lt;BookLoanRecord&gt; bookLoanRecordList_way1 = personList.stream()
                  .map(person -&gt; person.getBooks().stream().map(BookLoanRecord::createLoanRecordStaticVersion).collect(Collectors.toList()))
                  .flatMap(Collection::stream)
                  .collect(Collectors.toList());
  
          List&lt;BookLoanRecord&gt; bookLoanRecordList_way2 = personList.stream()
                  .map(person -&gt; person.getBooks().stream().map(Book::createLoanRecordNotStaticVersion).collect(Collectors.toList()))
                  .flatMap(Collection::stream)
                  .collect(Collectors.toList());
  
          List&lt;BookLoanRecord&gt; bookLoanRecordList_way3 = personList.stream()
                  .map(Person::getBooks)
                  .flatMap(Collection::stream)
                  .map(Book::createLoanRecordNotStaticVersion)
                  .collect(Collectors.toList());
      }
  }
  </code></pre>
  <p>Class Book</p>
  <pre><code>public class Book {
  
      String title;
      String author;
  
      public Book(String title, String author) {
          this.title = title;
          this.author = author;
      }
  
  //getters &amp; setters
      
  
      // The same method as createLoanRecordStaticVersion but without static
      public  BookLoanRecord createLoanRecordNotStaticVersion(){
          return new BookLoanRecord(this.title, this.author, LocalDateTime.now());
      }
  }
  </code></pre>
  <p>Class BookLoanRecord</p>
  <pre><code>public class BookLoanRecord {
  
      String title;
      String author;
      LocalDateTime dateTime;
  
      public BookLoanRecord(String title, String author, LocalDateTime dateTime) {
          this.title = title;
          this.author = author;
          this.dateTime = dateTime;
      }
  
      //getters &amp; setters
  
      //Needs to be static if we want to use it as method reference in stream
      public static BookLoanRecord createLoanRecordStaticVersion(Book book){
          return new BookLoanRecord(book.title, book.author, LocalDateTime.now());
      }
  
  }
  </code></pre>
  <p>Both method referances work fine in this case (BookLoanRecord::createLoanRecordStaticVersion, Book::createLoanRecordNotStaticVersion).</p>
  <p>Case 2:</p>
  <pre><code>public class Main {
      public static void main(String[] args) {
          //  returnTime();
          generateRandomPerson();
      }
  
  
  
      public static Person generateRandomPerson() {
  //        return PersonGenerator.generateRandomPerson(); //all good here
          return PersonGenerator::generateRandomPerson;  //error: 
  
      }
  }
  </code></pre>
  <p>PersonGenerato class:</p>
  <pre><code>public class PersonGenerator {
  
      private static final Random random = new Random();
  
      private static final List&lt;String&gt; femaleNamesList = List.of(&quot;Diana&quot;, &quot;Daria&quot;, &quot;Ola&quot;, &quot;Ala&quot;, &quot;Julka&quot;, &quot;Monika&quot;, &quot;Magda&quot;);
      private static final List&lt;String&gt; maleNamesList = List.of(&quot;Adam&quot;, &quot;Tomek&quot;, &quot;Arek&quot;, &quot;Olek&quot;, &quot;Alek&quot;, &quot;Julek&quot;);
      private static final List&lt;String&gt; surnameList = List.of(&quot;Newton&quot;, &quot;Smith&quot;, &quot;Nowak&quot;, &quot;Kowalczyk&quot;, &quot;Robinson&quot;);
  
      public static Person generateRandomPerson(){
  
          Sex sex = Sex.getRandomSex();
          String surname= generateRandomSurname();
          String name = generateRandomName(sex);
  
          return new Person(name, surname, sex);
      }
  
      private static String generateRandomSurname(){
          return surnameList.get(random.nextInt(surnameList.size()));
      }
  
      private static String generateRandomName(Sex sex){
          if (sex == Sex.MALE){
              return maleNamesList.get(random.nextInt(maleNamesList.size()));
          } else {
              return femaleNamesList.get(random.nextInt(femaleNamesList.size()));
          }
      }
  }
  </code></pre>
  <p>Adding lacking classes:</p>
  <pre><code>public class Person {
  
      private String name;
      private String surname;
      private Sex sex;
  
      public Person(String name, String surname, Sex sex) {
          this.name = name;
          this.surname = surname;
          this.sex = sex;
      }
  
      public Person() {
      }
  
      // setters and getters 
  
  }
  </code></pre>
  <p>and</p>
  <pre><code>public enum Sex {
      MALE,
      FEMALE;
  
      public static Sex getRandomSex(){
          Random random = new Random();
          return values()[random.nextInt(values().length)];
  
      }
  }
  </code></pre>
  <p>And here I'm getting this error:
  <em>Person is not a functional interface</em>
  in method generateRandomPerson()</p>
  <p>The question is why ? I don't understand why case 1 is ok and I'm getting an error in case 2.
  Why it wants class Person to be functional interface?
  What needs to be change to use method referance in case 2 as well ?</p>