enum 枚举使用

news/2024/5/18 5:23:20 标签: enum, 枚举

 

enum 枚举的使用


import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by tkzc on 2016/12/14.
 */
public enum QuoteType implements Serializable {

    @SerializedName("0")
    All("默认",0),
    @SerializedName("1")
    TL("整车",1),
    @SerializedName("2")
    LTL("零担",2);

    private String name;
    private int index;

    private QuoteType(String name, int index) {
        this.name = name;
        this.index = index;

    }

    public  String getDesc(){
        return  this.name.toString();
    }


    public  Short value (){
        return    Short.valueOf(String.valueOf(this.index));
    }

    private static final Map<String, QuoteType> stringToEnum = new HashMap<String,QuoteType>();
    static {
        // Initialize map from constant name to enum constant
        for(QuoteType myenum : values()) {
            stringToEnum.put(myenum.value().toString(), myenum);
        }
    }

    public  static QuoteType valueOf(Short s){
        return  stringToEnum.get(s.toString());
    }

}

values、valueOf方法

Compiled from "Color.java"
public final class Color extends java.lang.Enum<Color> {
  public static final Color Red;
  public static final Color Green;
  public static Color[] values();
  public static Color valueOf(java.lang.String);
  static {};
}


http://www.niftyadmin.cn/n/1204918.html

相关文章

JAVA VirtualVM远程监控配置

Virtual VM是JDK6 Update7之后推出的工具&#xff0c;有集合其它JDK工具的倾向&#xff0c;目前JDK7的版本已经支持绝大部分的监控功能&#xff0c;好像还不能像Jprofile和Youkit那样支持实时跟踪内存堆栈来定位内存泄露问题。 对于远程应用的连接&#xff0c;Virtual VM提供两…

VeryNginx(centos7)

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778我的博客已迁移到xdoujiang.com请去那边和我交流VeryNginx功能强大并且拥有友好界面的NginxNginx 运行状态分析每秒请…

IDEA开发Java 404解决办法

将Web Resource Directory选到当前项目web或webRoot或webapp下&#xff0c;如图所示项目中目录是web

ckeditor + ckfinder 404 处理

最近网站中用到了图文混排的功能&#xff0c;按照网上步骤配置好了后&#xff0c;始终不能正常使用&#xff0c;各种调试&#xff0c;最后发现了问题所在。 根据网上教程配置好ckeditor ckfinder后&#xff0c;如果点击浏览服务器还是出现404&#xff0c;检查ckfinder-jar包有…

【Microsft】windbg简单使用手册

symbol file path: SRV*C:\symbols*http://msdl.microsoft.com/download/symbols 参考链接: http://www.cnblogs.com/minggeer/p/4281210.html 本文转自daniel8294 51CTO博客&#xff0c;原文链接&#xff1a;http://blog.51cto.com/acadia627/1964963&#xff0c;如需转载请自…

Maven 安装本地jar包 到本地仓库

以&#xff08;管理员身份打开命令行&#xff09; mvn install:install-file -DfileD:\yfsoft\WEB-INF\lib\CKFinder-2.5.1.jar -DgroupIdcom.ckfinder -DartifactIdckfinder -Dversion2.5.1 -Dpackagingjar

Java JDK8 Stream流操作

一、流的初始化&#xff1a; 1、Stream.of(T t); 2、Arrays.stream(strArray); 3、list.stream(); 二、流的操作&#xff1a; List<String> strList new ArrayList<>(); strList.add("aaa"); strList.add("bbb"); strList.add("c…

HttpConnection简单学习

我们在调用远程接口时&#xff0c;有时候用httpClient。当然我们也可以用java自带的一个类来做这个操作&#xff0c;这里有一个简单的例子&#xff1a; 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162…