Java byte type in enum constructor
enums, java
Solution
Just `cast` to a `byte`, like so:
public enum Rank {
TEN("Ten", (byte)1),
NINE("Nine", (byte)2),
EIGHT("Eight", (byte)0),
SEVEN("Seven", (byte)0);
private final String name;
private final byte point;
private Rank(String name, byte point)
{
this.name = name;
this.point = point;
}
Problem
``` public enum Rank { TEN("Ten",1), NINE("Nine",2), EIGHT("Eight",0), SEVEN("Seven",0); private final String name; private final int point; /* * @param rank should be byte */ private Rank(String name,int point) { this.name=name; this.point=point; } ``` How to replace int to byte in point. One way i can think of is using `TEN("Ten",Byte.parseByte("1"));` Is there any better or/and shorter approach?