JDK 7: Proposition 13 : Accès aisé aux propriétés
Accès aisé aux propriétés
Proposition 1 :
En utilisation le point comme séparateur
Code:
1 2 3 4 5 6 7 8
|
public class Person {
public property String forename;
public property int age;
}
Person p = new Person();
p.forename = "Stephen"; // calls setter
String str = p.forename; // calls getter |
Proposition 2 :
En utilisant => comme séparateur
Code:
1 2 3 4 5 6 7 8
|
public class Person {
public property String forename;
public property int age;
}
Person p = new Person();
p=>forename = "Stephen"; // calls setter
String str = p=>forename; // calls getter |
Proposition 3 :
En utilisant # comme séparateur
Code:
1 2 3 4 5 6 7 8
|
public class Person {
public property String forename;
public property int age;
}
Person p = new Person();
p#forename = "Stephen"; // calls setter
String str = p#forename; // calls getter |