I'm struggling to understand how these two snippets of code are different and why one fails to compile while the other one throws and exception at RT. Could somebody explain please?
#1
Code: Select all
List<Book> books = getBooksByAuthor("Ludlum");
Collections.sort(books, (b1, b2)->b1.getTitle().compareTo(b2.getTitle()));//1
Collections.sort(books); //2
Code: Select all
List<Book> books = getBooksByAuthor("Ludlum"); books.stream().sorted().forEach(b->System.out.println(b.getIsbn())); //1