除了性能外,包装类型有什么缺点吗? [英] Are there any disadvantages to wrapper types besides performance?

查看:188
本文介绍了除了性能外,包装类型有什么缺点吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的工作线上,我主要从事具有大量数据库代码的业务应用程序。我通常不会写数字捣蛋的科学逻辑。

In my line of work I'm mostly working on business applications that have a lot of database code. I don't usually write number crunching scientific logic.

这让我想知道 - 是否一个好主意,总是使用包装类型在我的实体类?我发现自己经常将原语转换为包装器。相反,我不能想到一个情况,我不能做没有一个原始。

This makes me wonder - would it be a good idea to always use wrapper types in my entity classes? I've found myself frequently converting primitives to wrappers. On the contrary I can't think of a case where I couldn't do without a primitive.

如果我声明我的实体中的字段是包装器,那么从db读取的数据将被我的持久层自动映射到这些字段上,从而节省了手动创建它们。

If I declared the fields in my entities to be wrappers the data read from db would be automatically mapped onto these by my persistence layer, thus saving me the trouble of having to create them manually.

有些事情只来自经验,因此我问你们的人,有人试过去这种方法吗?是否有任何问题?

Some things only come through experience hence I'm asking you folks, has anyone tried going with this approach? Are there any problems with it?

我不关心性能,但从良好实践/架构的角度来询问这个问题。 / p>

I'm not concerned about performance but am asking this from good practice/architecture point of view.

推荐答案

封装与原始

优点


  • 可与泛型使用

  • 支持许多其他方法。

缺点


  • 使用更多cpu

  • / li>
  • 表示在某些情况下,输入的值可以更长。 null


  • uses more cpu
  • uses more memory
  • implies the value can be null
  • is longer to type in some cases.

这篇关于除了性能外,包装类型有什么缺点吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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