0

I have I quick question, say I have this class:

public enum Files {
    FILE_A, FILE_B;
}

Now FILE_A is a "Files", but being a "File" would be more intuitive. To example, when using a foreach, I need to use something like this:

for (Files file : Files.values()) {

}

Where File would be better(in my opinion). Is there a way of calling objects of a class different than the class itself? Like calling object of the class/enum "Files" "File". With classes I had the idea to do something like this:

public class A extends B {
    public static final FILE_A;
}

public class B {

}

Now every A is also a B, but that is not a clean way and doesn't work with enums. Is there another way?

GGG
  • 35
  • 4
  • 1
    Made me laugh: `class A extends B`. But, no, there are no aliasing options in Java, but maybe a common superinterface will do the trick. – Sotirios Delimanolis Jun 20 '14 at 21:50
  • You should learn Java basics first... – Luiggi Mendoza Jun 20 '14 at 21:51
  • I did, I'm just curious! – GGG Jun 20 '14 at 21:53
  • 3
    Why don't you simply rename Files to File? – JB Nizet Jun 20 '14 at 21:53
  • I don't really know what do you mean when using the verb `call`... – A4L Jun 20 '14 at 21:56
  • Curious about what? First of all, there's already a class `File` in JDK so you should not create another class with that name or with the same name of the JDK. Second: `public static final FILE_A` doesn't compile. From your last statement, I'm not sure if you want your `enum` to extend from another class. – Luiggi Mendoza Jun 20 '14 at 21:58
  • See also this related C# question: http://stackoverflow.com/questions/1405851/enum-naming-convention-plural – Raedwald Jun 21 '14 at 03:17
  • possible duplicate of [Naming of enums in Java: Singular or Plural?](http://stackoverflow.com/questions/15755955/naming-of-enums-in-java-singular-or-plural) – Raedwald Jun 21 '14 at 03:18

2 Answers2

1

Class names should be in singular (in most cases).

Also, giving enum values a prefix isn't common in java.

Jimmy T.
  • 4,033
  • 2
  • 22
  • 38
1

The enum class name (like most class names) is usually singular rather than plural. Take TimeUnit as an example. Referring to instances, then, is a more grammatically natural TimeUnit.SECONDS rather than the awkward TimeUnits.SECONDS.

Brett Okken
  • 6,210
  • 1
  • 19
  • 25