从 EJB 返回枚举

发布于 2024-11-16 15:23:01 字数 926 浏览 4 评论 0原文

我希望使用 Enum 从 EJB 返回代码和消息。目前仅返回整数值Code。 由于我们有多个客户端应用程序,并且当 EJB 公共类更新时客户端并不总是更新,反之亦然。如果客户端的枚举类型不同步会发生什么?

如果我在客户端有 Enum 的旧定义,在 EJB 端有新定义,反之亦然,它会起作用吗?

例如 客户端:

 public enum Color {
 WHITE(21, "White"), BLACK(22, "Black");

 private int code;
private int message;

 private Color(int c, String message) {
   code = c;
   message = m;
 }

 public int getCode() {
   return code;
 }

public String getMessage(){
 return message;
}

EJB 端:

 public enum Color {
 WHITE(21, "White"), BLACK(22, "Black"), RED(23, "Red");

 private int code;
private int message;

 private Color(int c, String message) {
   code = c;
   message = m;
 }

 public int getCode() {
   return code;
 }

public String getMessage(){
 return message;
}

我的 EJB 方法是:

public Color getBestColor(); 

并返回:

Color.WHITE

I'm looking to use Enum's to return both Codes and Messages from an EJB. Currently only an integer value Code is returned.
As we have more than one client app and the clients are not always updated when the EJB common classes are and vica versa. What will happen if the Enum types on the Client side become out of sync?

Will it work if I have an old definition of an Enum on the client side, and a new definition on the EJB side and vica versa?

E.g
Client side:

 public enum Color {
 WHITE(21, "White"), BLACK(22, "Black");

 private int code;
private int message;

 private Color(int c, String message) {
   code = c;
   message = m;
 }

 public int getCode() {
   return code;
 }

public String getMessage(){
 return message;
}

EJB side:

 public enum Color {
 WHITE(21, "White"), BLACK(22, "Black"), RED(23, "Red");

 private int code;
private int message;

 private Color(int c, String message) {
   code = c;
   message = m;
 }

 public int getCode() {
   return code;
 }

public String getMessage(){
 return message;
}

And my EJB method is:

public Color getBestColor(); 

And returns:

Color.WHITE

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぃ弥猫深巷。 2024-11-23 15:23:01

如果客户端枚举定义具有您发送的值,它将正常工作(例如白色)。如果客户端没有该值,那么您将在客户端收到 IllegalArgumentException(例如 RED)。 (有关枚举序列化的详细信息请参见此处)。

If the client enum definition has the value you send, it will work fine (e.g. WHITE). if the client does not have the value, then you will get an IllegalArgumentException on the client side (e.g. RED). (details on enum serialization here).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文