java - Seperate Enum file wont accept variables -
i've created enum.java
file , errors when creating variables. in other .java files, none of these errors appear. within enum foo, thing causes no errors if foo constructor takes no parameters , thatthere no other variables within enum.
the errors range string beingness invalid modifier , boolean deleted.
package com.foo.bar public enum foo { string foo; boolean isbarable; foo(string foo, boolean isbarable) { this.foo = foo; this.isbarable = isbarable; } }
you're missing of import element of enum: enum instances.
public enum foo { // instances go here ; // **** semicolon needed private string foo; private boolean isbarable; private foo(string foo, boolean isbarable) { this.foo = foo; this.isbarable = isbarable; } }
shoot, adding semicolon lone solve compilation error, without enum instances, enum useless.
e.g.,
public enum foo { bar("bar", true), baz("baz", false) ; private string foo; private boolean isbarable; private foo(string foo, boolean isbarable) { this.foo = foo; this.isbarable = isbarable; } }
java enums
No comments:
Post a Comment