value type paradox

B

bobby

Hello group,

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?

can clarify this for me?Class or Object

Thanks
B.
 
M

markspace

bobby said:
Hello group,

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?

can clarify this for me?Class or Object


Google is your friend:

http://en.wikipedia.org/wiki/Value_type

"In object-oriented programming, a value type is a data type that can
exist outside dynamic memory allocation."


I'd say in Java value types are primitives, and that's it. I'm not sure
of the definition of "value type" on Wikipedia, though. It's got a note
about further discussion being needed. It might be a term from another
programming language (C#?) leaking into the general programming vernacular.
 
B

bobby

But All types are derived from System.ValueType which, in turn,
inherits from class Object.Some seems that it is an object of class.
 
D

Daniel Pitts

bobby said:
But All types are derived from System.ValueType which, in turn,
inherits from class Object.Some seems that it is an object of class.
System.ValueType is not a Java class.
Object.Some is not a Java class.

If you consider a Value Type as an type with Value semantics (the object
state is the identity of the object), then you're looking at immutable
objects or primitives, or reference values themselves. At least, that's
how it is in Java.

In C++, you can define a class that has value semantics (deep copy,
pass-by-value, rarely makes sense to have a pointer to the object,
comparison is a primitive operation, etc...). I'm sure this is the case
in other languages too.
 
S

Stefan Ram

Daniel Pitts said:
If you consider a Value Type as an type with Value semantics (the object
state is the identity of the object)

I'd explain that this way:

Let »v« be a function from the type T into a set S. (This is
not a method nor a set in the sense of Java, but a function
and set in the sense of mathematics, so there does not have
to be a definition of v or S in Java code.)

Let x and y be objects of the type T.

We call v(x) the »v value of x«.

Iff the result and behavior of any expression¹ with
subexpressions of the value type depends only on the v value
of these subexpressions, then T is a value type with regard
to v.

For example, x.equals( y ) (in Java code) iff v(x) is v(y)
(in our set S outside of Java code).

1) Except for some special cases, such as »x == y«.

(This definition was just invented by me according to my
personal interpretation of this notion.)
 
A

Arne Vajhøj

Eric said:
bobby said:
bobby wrote:
Hello group,
what is a value type in C++ or Java or C#? [...]
Google is your friend:

http://en.wikipedia.org/wiki/Value_type

"In object-oriented programming, a value type is a data type that can
exist outside dynamic memory allocation."

I'd say in Java value types are primitives, and that's it. I'm not sure
of the definition of "value type" on Wikipedia, though. It's got a note
about further discussion being needed. It might be a term from another
programming language (C#?) leaking into the general programming
vernacular.

But All types are derived from System.ValueType which, in turn,
inherits from class Object.Some seems that it is an object of class.

No. Perhaps this is true in some of the other languages you ask
about, but it is not true of Java.

He is talking about .NET !

Arne
 
M

markspace

bobby said:
But All types are derived from System.ValueType which, in turn,
inherits from class Object.Some seems that it is an object of class.


I have to agree with the others: I have no idea what you are talking
about vis-a-vis System.ValueType.

As for Object.Some ... most English users put two spaces after the
period that ends a sentence.
 
A

Arne Vajhøj

bobby said:
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?

can clarify this for me?Class or Object

Everything in your question seems to relate to .NET and C#.

I suggest you try and post to:
microsoft.public.dotnet.languages.csharp

Arne
 
E

Eric Sosman

Arne said:
Eric said:
bobby said:
[,,,]
But All types are derived from System.ValueType which, in turn,
inherits from class Object.Some seems that it is an object of class.

No. Perhaps this is true in some of the other languages you ask
about, but it is not true of Java.

He is talking about .NET !

Then he should talk about it in a Microsoft forum, not
here. This group is dedicated to solely to Fortran.
 
A

Arne Vajhøj

Eric said:
Arne said:
Eric said:
bobby wrote:
[,,,]
But All types are derived from System.ValueType which, in turn,
inherits from class Object.Some seems that it is an object of class.

No. Perhaps this is true in some of the other languages you ask
about, but it is not true of Java.

He is talking about .NET !

Then he should talk about it in a Microsoft forum, not
here. This group is dedicated to solely to Fortran.

WRITE(*,*) 'FUNNY'
END

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,955
Messages
2,570,117
Members
46,705
Latest member
v_darius

Latest Threads

Top