• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

about .class for primitive types and void

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, everyone.

I found that .class could be applied to primitives and void. I completely don't understand what . means then. I always thought that . is like c++ ->, so it returning a reference to a field and then dereferecing it. But how this can be applied to the primitive types? Or does this mean that primitive types in java are also objects? Please, advise. Many thanks.
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gasan Gouseinov wrote:Or does this mean that primitive types in java are also objects?



No. They are not. People debate that java is not 100% object oriented because of this.
 
Gasan Guseynov
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What . (dot) means then?
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The C language has been called "high level assembler", because there's almost always a one-to-one correspondence between a language construct and specific assembly instructions. Since the first C++ compiler was a special preprocessor for a C compiler, C++ is pretty much the same way. The dot operator does indeed translate into a very specific kind of dereferencing.

But Java is different; it's a somewhat higher level language, and many language constructs don't map directly onto virtual machine instructions. Many operators give rise to different code depending on how they're used. The dot operator in Java is definitely one of those.

In Java, "dot class" construct is handled entirely by the compiler. Although it might look like it, no class actually has a member named "class", and could not, of course, since "class" is a reserved word in Java. Anyway, when the compiler sees ".class" attached to a type name, it know how to substitute the appropriate Class object. For primitives, there are Class objects available as constants named TYPE in the corresponding wrapper classes -- i.e. int.class is changed to java.lang.Integer.TYPE . For other types, the compiler creates a private member variable in the class being compiled to hold the Class object, and generates code to initialize that member using Class.forName() .
 
reply
    Bookmark Topic Watch Topic
  • New Topic