1
votes

I thought I understand concept of class(object) Class, but reading about it in Java API, I found this:

The primitive Java types (boolean, byte, char, short, int, long, float, and double), and the keyword void are also represented as Class objects.

2
docs.oracle.com/javase/7/docs/api/java/lang/Void.html The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the Java keyword void.Suresh Atta
What exactly you are wondering about? I meant, you don't get the point of object and class concept OR primitive type classes?NawaMan
@NawaMan I guess it's primitive type classes. When I read quote above, I thought I misunderstood concept of Class. I didn't know connection of primitive types with Class.misty
@LazyLady I recommend you to revise the question to reflex that. :-DNawaMan

2 Answers

2
votes

The phenomenon on autoboxing and unboxing is what you're looking for. In java there are some primitives for comfort purposes. They all have wrapper classes. These are: Integer, Double, Boolean etc.

Autoboxing is responsible for wrapping primitives into Wrappers each time the Wrapper is expected but a primitive is passed. On the other hand unboxing comes. When it's a primitive expected but Wrapper passed unboxing will manage to extract the proper value.

It's well described here

Example:

Integer one = new Integer(1);
int i = one.intValue();

void printInteger(int i) {
    System.out.println(i);
}

printInteger(one);

No exception will be thrown - one will be unboxed to int and printed.

-1
votes

The difference is that the primitives are just zones of memory and when you are using the keyworks you are telling to compiler how 'to see' these areas. While with the correspondend objects such as Integer or Character are objects that have methods to work with these types and they are seen as such as objects