1

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.

misty
  • 123
  • 13
  • 2
    https://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 Aug 03 '16 at 17:04
  • 1
    https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#TYPE – fabian Aug 03 '16 at 17:05
  • 2
    What exactly you are wondering about? I meant, you don't get the point of object and class concept OR primitive type classes? – NawaMan Aug 03 '16 at 17:07
  • @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 Aug 03 '16 at 17:11
  • 1
    @LazyLady I recommend you to revise the question to reflex that. :-D – NawaMan Aug 03 '16 at 17:22
  • @LazyLady did you read my answer with an example? Are you still interested? Feel free to ask about more details - I'll explain further if still needed. – xenteros Aug 09 '16 at 13:08
  • Yes, I have read it, but I don't think that is my answer. I know what are autoboxing and outboxing. Maybe I just don't understand all of this - you can explain it a bit more. – misty Aug 10 '16 at 21:05

2 Answers2

1

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.

xenteros
  • 15,586
  • 12
  • 56
  • 91
  • This is not about Autoboxing. The classes Integer etc. were present from the beginning of Java on. Not only since Autoboxing was introduced. – gsl Aug 09 '16 at 13:32
  • @gsl I can agree that it's not **only** about autoboxing. As it was introduced to `java 1.5` we all use it. – xenteros Aug 09 '16 at 13:34
  • This does not answer the question. OP is not looking for the autoboxing concept explanation.. rather they are baffled with the basic constructs of the language. – Giorgi Tsiklauri Oct 02 '20 at 05:39
-1

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

Harald
  • 3,110
  • 1
  • 24
  • 35
P.Carlino
  • 661
  • 5
  • 21