Jump to content

  • Log In with Google      Sign In   
  • Create Account

trouble making an enum in java (weird error(s))


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Enerjak   Members   -  Reputation: 235

Like
0Likes
Like

Posted 30 October 2012 - 08:53 AM

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.

Sponsor:

#2 rip-off   Moderators   -  Reputation: 8726

Like
1Likes
Like

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 Enerjak   Members   -  Reputation: 235

Like
0Likes
Like

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 ppgamedev   Members   -  Reputation: 311

Like
1Likes
Like

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.


#5 Enerjak   Members   -  Reputation: 235

Like
0Likes
Like

Posted 30 October 2012 - 10:01 AM

thanks alot.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS