How to declare and use static enum in Java -
i googled around question, not find relevant example matches situation.
public class game{ static enum tile { static //syntax error, insert "identifier" complete enumconstantheader { dirt = new tile("dirt", 1); //cannot instantiate type game.tile grass = new tile("grass", 2); rock = new tile("rock", 3); exit = new tile("exit", 4); player = new tile("player", 5); player_left = new tile("player_left", 6); player_right = new tile("player_right", 7); //for above declared fields, getting compile time errors : /* multiple markers @ line - cannot instantiate type game.tile - dirt cannot resolved variable */ tile[] arrayoftile = new tile[8]; arrayoftile[0] = empty; arrayoftile[1] = dirt; arrayoftile[2] = grass; arrayoftile[3] = rock; arrayoftile[4] = exit; arrayoftile[5] = player; arrayoftile[6] = player_left; arrayoftile[7] = player_right; $values = arrayoftile; } } } in case have declared enum depicted above. receiving lots of compile errors have inserted comments in above code. can point me in right direction solve please?
i follow standard enum tutorial
http://docs.oracle.com/javase/tutorial/java/javaoo/enum.html
have @ example planet
public enum planet { mercury (3.303e+23, 2.4397e6), venus (4.869e+24, 6.0518e6), earth (5.976e+24, 6.37814e6), mars (6.421e+23, 3.3972e6), jupiter (1.9e+27, 7.1492e7), saturn (5.688e+26, 6.0268e7), uranus (8.686e+25, 2.5559e7), neptune (1.024e+26, 2.4746e7); private final double mass; // in kilograms private final double radius; // in meters planet(double mass, double radius) { this.mass = mass; this.radius = radius; } there values() method defined you. don't need yourself.
Comments
Post a Comment