Map.java.lang.Object的替代方法 [英] Alternative to Map of java.lang.Object

查看:92
本文介绍了Map.java.lang.Object的替代方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我必须构建一个新的Java应用程序,并且有一种情况,我倾向于将对象映射用于所有类型的转换.我只是不喜欢这个主意,但却找不到更好的解决方案.

So, I have to build a new Java application and I have a scenario where I'm inclined to use a Map of Objects with casts all around. I just don't like this idea though, but can't figure out a better solution.

在这种情况下:我有一些用户输入以及定义了要采取的操作的标记.首先,基于标签,用户输入将包含一个或多个对象,然后将其传递到验证器机器进行处理.这些验证器在某种程度上是通用的,因此它们可以用于一个或多个标签.那就是Map出现的地方,它将是验证者的输入,因为他们知道要使用地图的哪个键.

Here's the scenario: I have some user input along with a tag that defines the action to be taken. First, based on the tag, the user input will be enriched with one or more objects, and then it will be passed along to a validator machine to be processed. These validators are somewhat generic, so they can be of use to one or more tags. That's where the Map comes in, it will be the validators input, because they know which key of the map to use.

我一直在研究命令链"设计模式,但是它使用单个请求,在我的情况下,请求可能会根据标签而有所不同.另外,我的验证器机器已经实现了主要目的.

I have been looking at the Chain of Command design pattern, but it uses a single request, and in my case the request can vary depending on the tag. Also, it's main purpose is already achieved with my validator machine.

是否有更好的解决方案?

Is there a better solution for this?

推荐答案

如果您不想编写自己的类型安全的异构容器,请考虑Netty的

If you don't want to write your own typesafe heterogeneous container, consider Netty's AttributeMap, available in the netty-common library.

这篇关于Map.java.lang.Object的替代方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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