容器和包装器的区别 [英] Difference between container and wrapper
问题描述
在编程语言(例如 Java)中,container
和 wrapper
有什么区别(或者有区别).我听说这两个术语都含糊其辞.
In a programming language (e.g. Java), what's the difference between container
and wrapper
(or is there a difference). I've heard both the terms used vaguely.
推荐答案
在编程语言中,container这个词通常用于可以包含多个元素的结构,例如 Map、集合或列表.这些结构通常提供像 contains
这样的方法,如果对象可以包含多个项目,这些方法在语义上是合适的.
In programming languages the word container is generally used for structures that can contain more than one element, for example a Map, a Set or a List. These structures normally provide methods like contains
, that are semantically suitable if the object can contain more than one item.
包装器 是包装单个对象以提供更多功能和接口的东西.典型的例子是 Integer
类,它在 Java 中包装了基本类型 int
.
A wrapper instead is something that wraps around a single object to provide more functionalities and interfaces to it. The typical example is the Integer
class that in Java wraps the base type int
.
这篇关于容器和包装器的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!