2013-03-31 62 views
0

下面的java代碼不能在eclipse中編譯。我在這裏做錯了什麼?如果該方法只返回int而不是enum,則一切正常,因此它基本上設置正常。問題在於引入枚舉返回類型。爲什麼這個枚舉類型沒有正確解析?

public class myclass { 
    public enum mytype { 
     mytype2, 
     mytype1, 
    }; 
    public static mytype retmytype() { 
    return mytype2; 
    } 
} 

//in another class 
myclass.mytype t = myclass.retmytype(); //ERROR - myclass.mytype cannot be solved 
+1

使用'camelCase'男人! –

+0

@LuiggiMendoza內部枚舉總是靜態的,即使沒有指定 – Daniel

+0

@Luiggi門多薩如果一個枚舉是一個類的成員,它是隱式靜態的 – Mik378

回答

1

嘗試通過return mytype.mytype2;

更換return mytype2;順便說一句,你應該遵循Java的命名約定;)

我想你忘記了一個主要方法(或程序中的流中的任何其他調用的方法)。 試試這個:

public class myclass { 
    public enum mytype { 
     mytype2, 
     mytype1, 
    }; 
    public static mytype retmytype() { 
    return mytype.mytype2; 
    } 
    public static void main(String[] args){ 
    myclass.mytype t = myclass.retmytype(); 
    } 
} 
+0

同樣的問題。該錯誤在呼叫者級別被標記。 – glutz

+0

@glutz例如,您可能忘記用主要方法來包圍您的呼叫;)。你可能會「打電話」。 – Mik378

+0

@glutz我更新了我的答案。 – Mik378