Are there any disadvantages to wrapper types besides performance?

萝らか妹 提交于 2020-01-06 07:23:30

问题


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.

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?

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


回答1:


Wrappers vs Primitives

Pros

  • can be used with generics
  • supports many additional methods.

Cons

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


来源:https://stackoverflow.com/questions/12640826/are-there-any-disadvantages-to-wrapper-types-besides-performance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!