Stuck in an enum in front of a blacksmith

I proceeded to study Java according to the book "Practical Java Gamenics Easy Master Kindle Edition", but it was stopped again by haste. ..

D:\Study>javac -encoding UTF-8 edu\rpg\personal\GenderClass.java edu \ rpg \ personal \ GenderClass.java: 3: Error: Enum cannot be instantiated public static GenderClass MALE = new Gender2 ("male"); ^ edu \ rpg \ personal \ GenderClass.java: 4: Error: Enum cannot be instantiated public static GenderClass FEMALE = new Gender2 ("female"); ^ 2 errors

I wrote it briefly using enum in WeaponType.java to list the types of weapons.

package edu.rpg.weapon;
public enum WeaponType {
  SWORD,
  HUNMER,
  KATANA
}

In Exercises12, I'm trying to create a Gender class to describe the gender of a String using an enumeration type, but in the middle of the story it becomes Gendere2.java, and it is explained in GenderClass.java. GenderClass.java

package edu.rpg.personal;
public class GenderClass {
  public static GenderClass MALE = new Gender2("Man");
  public static GenderClass FEMALE = new Gender2("woman");
  private String name;

  private GenderClass(String name) {
    this.name = name;
  }
  public String getName() {
    return this.name;
  }
}

Going around, it seems that errors are commonplace. The story goes on without touching this. In the story, I added a variable to count the population and explained the timing of instantiation, but it was a problem before that.

What did you do?

Is it okay because I learned a little about how to write markdown?

Recommended Posts

Stuck in an enum in front of a blacksmith
Quickly implement a singleton with an enum in Java
I got stuck in a clone of a two-dimensional array
Get stuck in a Java primer
Cast an array of Strings to a List of Integers in Java
Link Apache and Tomcat in a blink of an eye on CentOS 8
Find an approximation of cosx in Swift
A simple example of an MVC model
28th day of an engineer who will become a full-fledged person in 100 days
Measure the size of a folder in Java
A quick review of Java learned in class
Create a native extension of Ruby in Rust
What an inexperienced engineer who took a leave of absence from college learned in 2020
A story that got stuck with an error during migration in docker PHP laravel
Count the number of occurrences of a string in Ruby
One case of solving a migration error in Rails
Advantages of generating an Abstract Factory pattern with an enum
A quick review of Java learned in class part4
Let's write a Qiita article in org-mode of Emacs !!
The story of an Illegal State Exception in Jetty.
Get a list of classes in a Guava specific package
Addition of variables in iterative processing in a while statement
I wrote an overview of Chef in an easy-to-understand manner
A quick review of Java learned in class part3
A quick review of Java learned in class part2
A program (Java) that outputs the sum of odd and even numbers in an array