如何将int与枚举匹配 [英] How to match int to enum

查看:29
本文介绍了如何将int与枚举匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从 Android 中的本机代码接收 long 或 int 形式的返回值,我想将其转换或与 enum 匹配,以进行处理.是否可以 ?怎么样?

I am receiving return value in the form of long or int from Native code in Android, which I want to convert or match with enum, for processing purpose. Is it possible ? How?

推荐答案

如果你可以完全控制值和枚举,并且它们是顺序的,你可以使用枚举序数值:

If you have full control of values and enums, and they're sequential, you can use the enum ordinal value:

enum Heyo
{
  FirstVal, SecondVal
}

...later

int systemVal = [whatever];
Heyo enumVal = Heyo.values()[systemVal];

int againSystemVal = enumVal.ordinal();

这篇关于如何将int与枚举匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆