Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8845935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:51:12+00:00 2026-06-14T11:51:12+00:00

I recently learned that there are Class representations for the primitive types in the

  • 0

I recently learned that there are Class representations for the primitive types in the JVM. For example, int.class, double.class, and even a void.class.

What I don’t understand is why these are there. They don’t seem to serve any functional role. Using reflection, I searched through the classes, and they have no constructors, no methods, and no fields. For all intents and purposes, they seem empty and useless. The primitive type variables are not even instances of their respective classes, as indicated by the following returning false:

int a = 3;
int.class.isInstance(a);

So why do they exist? They must serve some purpose, maybe for the compiler or something, but whatever it is is completely beyond me. There is even an explicit reference to int.class in the Integer API (and likewise for each primitive type and its respective wrapper Object). I haven’t been able to find any reference to their existence, much less their use, in the JLS.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:51:14+00:00Added an answer on June 14, 2026 at 11:51 am

    What I don’t understand is why these are there.

    Consider the following:

    public int foo() {
        return 0;
    }
    
    ...
    
    Method method = someClass.getDeclaredMethod("foo");
    Class<?> clazz = method.getReturnType();
    

    Without a Class representation of int, what would the above return? It shouldn’t return Integer.class as they’re not the same thing. (Imagine trying to distinguish between methods which were overloaded, one with an int and one with an Integer parameter.)

    I’ve used these classes before to provide default values for arguments when calling them via reflection. Based on the parameter type, I’ve used null for any reference type, and some (boxed, obviously) primitive value for each of the primitive types.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Even though I am a long time C programmer, I only recently learned that
I recently learned that there are a plethora of WebSocket protocol specifications (a bunch
Recently I learned that there's an openjdk shark project, which uses llvm to make
I have recently learned that there are bugs in JDK7 for hotspot compiler optimization.
I recently learned that table valued functions are not allowed with Entity Framework 4.1.
I recently learned that all stl containers have swap function: i.e. c1.swap(c2); will lead
I've just recently learned about friend class concept in C++ (I've googled around for
I have learned recently that Export in Mathematica uses by default the Printout screen
UPDATE: I recently learned from this question that in the entire discussion below, I
I recently learned how to use automake, and I'm somewhat annoyed that my compile

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.