moooonaaaa
Messages postés56Date d'inscriptionjeudi 26 juillet 2007StatutMembreDernière intervention29 novembre 2010
-
26 mai 2008 à 23:30
moooonaaaa
Messages postés56Date d'inscriptionjeudi 26 juillet 2007StatutMembreDernière intervention29 novembre 2010
-
27 mai 2008 à 10:06
Salem,
j'ai fait l'enum suivant:
<!-- BEGIN TEMPLATE: bbcode_quote -->
Citation:
public enum acl {
ACL_NONE,
ACL_SRC_IP,
ACL_DST_IP,
ACL_MY_IP;
/** L'attribut qui contient la valeur associé à l'enum */
private final int value;
/** Le constructeur qui associe une valeur à l'enum */
private squid_acl(int value) {
this.value = value;
}
/** La méthode accesseur qui renvoit la valeur de l'enum */
public int getValue() {
return this.value;
}
};
<!-- END TEMPLATE: bbcode_quote -->et lors de compilation il m'affiche les errurs suivants:
<!-- BEGIN TEMPLATE: bbcode_quote -->
Citation:
squid_acl.java:2: cannot find symbol
symbol : constructor acl()
location: class acl
ACL_NONE,
^
acl.java:3: cannot find symbol
symbol : constructor acl()
location: class acl
ACL_SRC_IP,
^
acl.java:4: cannot find symbol
symbol : constructor acl()
location: class acl
ACL_DST_IP,
^
acl.java:5: cannot find symbol
symbol : constructor acl()
location: class acl
ACL_MY_IP,
^
<!-- END TEMPLATE: bbcode_quote -->alors j'ajoutela ligne suivante:
<!-- BEGIN TEMPLATE: bbcode_quote -->
Citation:
public acl{}
<!-- END TEMPLATE: bbcode_quote -->alors il me déclare le message d'erreur suivant:
<!-- BEGIN TEMPLATE: bbcode_quote -->
Citation:
squid_acl.java:3: '}' expected
ACL_NONE,
^
<!-- END TEMPLATE: bbcode_quote -->je travaille sous linux:opensuse10.3
cs_jojolemariole
Messages postés519Date d'inscriptionmercredi 21 mars 2007StatutMembreDernière intervention19 décembre 201625 27 mai 2008 à 08:25
squid_acl.java:2: cannot find symbol
symbol : constructor acl()
location: class acl
ACL_NONE,
^
acl.java:3: cannot find symbol
symbol : constructor acl()
location: class acl
ACL_SRC_IP,
^
acl.java:4: cannot find symbol
symbol : constructor acl()
location: class acl
ACL_DST_IP,
^
acl.java:5: cannot find symbol
symbol : constructor acl()
location: class acl
ACL_MY_IP,
=> Ca c'est parce que tu appelles un constructeur qui n'existe pas, en effet le constructeur doit porter le même nom que la classe.
public acl{}
=> Tu as oublié les parenthèses :
public acl() {}
"
je veux pas donner des numéros aux champs de l'enum.
je les mets dans l'ordre."
=> Ben, ils sont déjà dans l'ordre.
Par exemple si tu réduis ton enum au strict minimum :
<hr size="2" width="100%" />
public enum Acl {
ACL_NONE,
ACL_SRC_IP,
ACL_DST_IP,
ACL_MY_IP
}
Et bien tu peux utiliser ton enum de cette façon :
<hr size="2" width="100%" />
Acl acl1 = Acl.ACL_DST_IP;
System.out.println(acl1.getName());
System.out.println(acl1.toString());
System.out.println(acl1.ordinal());
La ligne en rouge te donnera le numero de l'Acl sans que tu aies besoin de le rajouter dans ton enum.
cs_DARKSIDIOUS
Messages postés15814Date d'inscriptionjeudi 8 août 2002StatutMembreDernière intervention 4 mars 2013130 27 mai 2008 à 07:04
Salut,
public enum acl {
ACL_NONE(1),
ACL_SRC_IP(200),
ACL_DST_IP(4),
ACL_MY_IP(60);
/** L'attribut qui contient la valeur associé à l'enum */
private final int value;
/** Le constructeur qui associe une valeur à l'enum */
public acl(int value) {
this.value = value;
}
/** La méthode accesseur qui renvoit la valeur de l'enum */
public int getValue() {
return this.value;
}
};
______________________________________
DarK Sidious
cs_DARKSIDIOUS
Messages postés15814Date d'inscriptionjeudi 8 août 2002StatutMembreDernière intervention 4 mars 2013130 27 mai 2008 à 08:23
Salut,
Alors à ce moment là, pourquoi tu te prends la tête à déclarer un champ valeur ??? Pas besoin de le mettre, Java attribuera automatiquement les valeurs à tes constantes d'enum !
______________________________________
DarK Sidious
Vous n’avez pas trouvé la réponse que vous recherchez ?