as you can tell from the title, i'm having a little trouble currently creating an enum in java as it gives weird errors such as:
http://puu.sh/1kuOn
not sure if you want the code also as it's right there in the image let me know.
4 replies to this topic
Sponsor:
#2 Moderators - Reputation: 5310
Posted 30 October 2012 - 09:16 AM
Please post the code. If you want to add fields, constructors or methods to a Java enumeration, you must end the list of enum names with a semicolon:
public enum Suit {
Hearts,
Spades,
Clubs,
Diamonds; // <-- Semicolon here indicates end of suits!
@Override
public String toString() {
// ...
}
}
#3 Members - Reputation: 193
Posted 30 October 2012 - 09:24 AM
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication1;
/**
*
* @author lucifir
*/
public class JavaApplication1 {
enum Suit
{
private final String colName;
private Suit(String name)
{
colName = name;
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
}
#4 Members - Reputation: 307
Posted 30 October 2012 - 09:45 AM
[source lang="java"]package javaapplication1;public class JavaApplication1 { enum Suit { HEARTS("Hearts"), SPADES("Spades"), CLUBS("Clubs"), DIAMONDS("Diamonds"); private final String colName; private Suit(String name) { colName = name; } } public static void main(String[] args) { // TODO code application logic here }}[/source]
Edited by ppgamedev, 30 October 2012 - 09:45 AM.






