![]() | Egalité, nullabilité, mutabilité, affichage |
var book = new Book("Da Vinci Code", "Dan Brown"); System.out.println(book.title + ' ' + book.author);Expliquer.
var weirdBook = new Book(null, "oops");
public void withTitle(String title) { this.title = title; }Comment faire alors ? (indice comme String.toUpperCase)
var b1 = new Book("Da Java Code", "Duke Brown"); var b2 = b1; var b3 = new Book("Da Java Code", "Duke Brown"); System.out.println(b1 == b2); System.out.println(b1 == b3);
var book1 = new Book("Da Vinci Code", "Dan Brown"); var book2 = new Book("Angels & Demons", new String("Dan Brown"));
var javaBook = new Book("Da Java Code", "Duke Brown"); System.out.println(javaBook);affiche
Da Java Code by Duke Brown
public class Book2 { private final String title; private final String author; public Book2(String title, String author) { this.title = title; this.author = author; } public static void main(String[] args) { var book1 = new Book2("Da Vinci Code", "Dan Brown"); var book2 = new Book2("Da Vinci Code", "Dan Brown"); System.out.println(book1.equals(book2)); } }Malheureusement, le main n'a pas le comportement attendu.
void swap(int[] array,int index1,int index2)