Enumerating Java byte types in constructors

public enum Rank {
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 with byte One method I can think of is to use ten ("ten", byte. Parsebyte ("1");

Is there a better or shorter way?

Solution

It only needs to be converted to one byte, as shown below:

public enum Rank {
    TEN("Ten",(byte)1),(byte)2),(byte)0),(byte)0);


    private final String name;
    private final byte point;

    private Rank(String name,byte point)
    {
        this.name = name;
        this.point = point;
    }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>