Why support for both int.class and Integer.TYPE?

  • Thread starter Brian J. Sayatovic
  • Start date
B

Brian J. Sayatovic

Years ago, when I first searched on how to get the class for a
primitive type, I learned the Integer.TYPE convention. At the time, I
assumed this was the only way, but it turns out it was the first way I
happened to find in my search results. You can also do int.class.

But why support both?

The Integer.TYPE javadocs say it's been around since JDK 1.1. I did
some Googling and found that the universal ".class" notation has also
been around since JDK 1.1. I could understand if one pre-dated the
other and they wanted to later add a better solution and not get rid
of the old one, but that doesn't appear to be the case.

So, again, why did we reach the point where both are supported?

Regards,
Brian.
 
C

Chris Uppal

Brian said:
Years ago, when I first searched on how to get the class for a
primitive type, I learned the Integer.TYPE convention. At the time, I
assumed this was the only way, but it turns out it was the first way I
happened to find in my search results. You can also do int.class.

But why support both?

The int.class expression is a hack introduced in the compiler which expands it
to Integer.TYPE.

There are a number of such hacks, some have real value, some are debatable,
some are clearly mistakes. I'd put int.class somewhere between the first two:
there is no real need for it but it does maintain consistancy with the
<classname>.class syntax that was introduced at the same time* (itself a hack,
of course, but probably worthwhile -- at least if you like the kitchen-sink
approach to language design).

*Real* Java -- by which I mean "what the JVM sees" -- has no such construction.

-- chris

[*] In java 1.2, IIRC (which is doubtfull).
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top