Re: value type pardox
On Oct 22, 11:22 pm, bobby <bsim...@gmail.com> wrote:
what is a value type in C++ or Java or C#? Is it a class or an
object? I can see one can call a method(For instance
ToString()) on an Int16 and so on;So is it an object?At the
same time we use Int16 to instantiate a variable Int16 a =new
Int16();So is it a class?
If it is a value type, it's a class; objects aren't types.
Other than that, "value type" is a design concept, and not
really part of any of the languages, at the language level. The
exact definition probably varies somewhat (and it only has
meaning what opposed to something else, e.g. an entity type),
but roughly speaking, it's a type for which identity isn't
important, a type for which a copy of the object is as good as
the original object. The classical example of the entity type/
value type dicotomy is BankAccount/MonetaryAmount. If someone
is crediting your account, you want it to be your account, and
not some copy that will disappear after the transaction; on the
other hand you really don't care whether the amount is a copy or
not, as long as your account is credited with it.
The basic types (in C++ and in Java, at least) are all value
types. In C++, a user defined value type will support copy and
assignment; in Java, it will be final and immutable (i.e. like
java.lang.String). Each language has its own idiom for
implementing them. (Note that by default, in C++, a class is a
value type; in Java, by default, it is an entity type.)
--
James Kanze