bonjour
j'ai ce bout de code
ce code retourne comme affichage:
Code java : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import java.util.Arrays; public enum Priority { ONE(1) { public String toString() { return "LOW"; } }, // (1) TWO(2), THREE(3) { public String toString() { return "NORMAL"; } }, // (2) FOUR(4), FIVE(5) { public String toString() { return "HIGH"; } }; // (3) private int pValue; Priority(int pValue) { this.pValue = pValue; } public static void main(String[] args) { System.out.println(Arrays.toString(Priority.values())); } }
[LOW, TWO, NORMAL, FOUR, HIGH]
mais je n'arrive a comprendre pourquoi ce résultat est ce qu'il excute automatiquement la méthode toStrong() overrided dans chaque enum constant lors de l'appel de Priority.values()
Partager