java newbie question

D

dave

Hello,

I'm studying Java, and now trying to make sense of the concept of
types.

Would it be correct to say:

a Java type is a classification of what could potentially be bound
to a Java variable

Also, The Java class Class really describes types. Would it have made
more sense to call this class Type instead of Class?
 
M

Mark Space

dave said:
a Java type is a classification of what could potentially be bound
to a Java variable

This works for me. I also think of type as how the JVM will interpret
any given bit pattern to which the variable is bound.

Also, The Java class Class really describes types. Would it have made
more sense to call this class Type instead of Class?

Hmm, but ints, chars, booleans and all the other primitives are also
types, but I don't think that Class describes them. Class only deals
with Java objects (most of the language, admittedly) but there are a few
types it doesn't abstract.

Also, generics are a type, but their type gets erased during
compilations. I don't think Class can represent the un-erased type.
 
P

Patricia Shanahan

Mark said:
This works for me. I also think of type as how the JVM will interpret
any given bit pattern to which the variable is bound.



Hmm, but ints, chars, booleans and all the other primitives are also
types, but I don't think that Class describes them. Class only deals
with Java objects (most of the language, admittedly) but there are a few
types it doesn't abstract.

Each of the wrapper types has a public static final TYPE field that
references the Class object for the corresponding primitive. For example:

"public static final Class<Integer> TYPE
The Class instance representing the primitive type int."

in class Integer. Class objects for primitives are important in some
reflection interfaces.
Also, generics are a type, but their type gets erased during
compilations. I don't think Class can represent the un-erased type.

I'm not sure generics count as a type, or anything else, in a running
program. They are effectively a form of compile-time assertion that
enables some extra checking.

Patricia
 
D

dave

Hmm, but ints, chars, booleans and all the other primitives are also
types, but I don't think that Class describes them. Class only deals
with Java objects (most of the language, admittedly) but there are a few
types it doesn't abstract.

Although primitive types aren't objects, they can return a Class
object. Example:

Class cl = int.class; // int.class is an object of type Class
 
L

Lew

Interfaces are also types, but not classes.

Class != type. Interface != type. Primitive != type.

Why are you interested in redefining the Java language? Is "class" such a bad
word?
 
D

dave

Interfaces are also types, but not classes.
Class != type. Interface != type. Primitive != type.

Why are you interested in redefining the Java language? Is "class" such a bad
word?

I'm not, I just asked if it made sense, it seemed logical to me,
although I admit I'm not a Java expert. In fact, you'll notice from
the title post I consider myself a Java "newbie", meaning there is no
way in hell I would think I'm smarter than the people at Sun who write
the Java specification!

My hope was to understand a bit more on exactly what types means in
Java.

Anyway, thanks especially Jeff Higgins for those links. Those pretty
much clear up the issues for me at least.
 
J

Jeff Higgins

I'm a newb2 and have had a lot of help from the good people
who frequent this group. I'm happy this "blind pig" was able to
help find an acorn.
JH
 
R

Roedy Green

Also, The Java class Class really describes types. Would it have made
more sense to call this class Type instead of Class?

Classes apply only to Objects. Type would be Objects plus primitives.

Class has some kludges to describe primitives, but for the most part
it applies only to classes.

So I think either the name Class or Type would have been appropriate.
 
M

Mark Space

dave said:
Although primitive types aren't objects, they can return a Class
object. Example:

Class cl = int.class; // int.class is an object of type Class


Well that's darn interesting. That's for pointing that out!
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top