[Java] enum-Variable initialisieren.

#2521342
Lesenswert?

Ich möchte gerne eine Aufzählungstyp-Variable initialisieren:

class Test{
 enum Typ { eins, zwei };

 protected Typ typus=zwei;

 public void methode()
 {
   switch(typus) {}
 }
};

Das Problem: das Attribut typus ist null, obwohl eine Initialisierung 
existiert. Woran liegt das?
Persönliche Seite #2521383
Lesenswert?

Bitte Orginalquellcode zeigen... so kompiliert das nicht mal.
1
class public class Test2 {
2
    enum Typ {
3
        eins,
4
        zwei
5
    };
6

7
    protected Typ typus = Typ.zwei;
8

9
    public void methode() {
10
        System.out.println(typus);
11
        switch (typus) {
12
        }
13
    }
14

15
    public static void main(String[] args) {
16
        new Test2().methode();
17
    }
18
};
funktioniert einwandfrei...

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren