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 7410183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:11:47+00:00 2026-05-29T06:11:47+00:00

How does this Java statement compile without warnings? Class<Integer> x = int.class; even though

  • 0

How does this Java statement compile without warnings?

Class<Integer> x = int.class;

even though

Integer.class != int.class

Edit: Putting it a different way, it seems as though Integer.class and int.class have nothing in common (see comments below), so why does it make sense for this assignment to be possible?

  • 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-05-29T06:11:48+00:00Added an answer on May 29, 2026 at 6:11 am

    After a whole lot of searching, I came across this little snippet in the JLS, section 15.8.2 Class Literals:

    If p is the name of a primitive type, let B be the type of an expression of type p after boxing conversion (§5.1.7). Then the type of p.class is Class<B>.

    The spec doesn’t explain why this is so, instead of Class<?> for example. I have also been unable to find any evidence that this is related to either generics or autoboxing.

    Integer is a first-class object whereas int is a primitive type, and most methods of Class such as isInstance, isAssignableFrom and cast which operate on Objects are invalid in the context of int.class. Consequently, I do not see any reason why the type of int.class is Class<Integer>.

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

Sidebar

Related Questions

Does this two Java statement lookup the class in the same way? this.getClass().getClassLoader().loadClass(Foo); and
Why does this test program result in a java.lang.IllegalMonitorStateException ? public class test {
(Java question) If I reference a field in an inner class, does this cause
Is there any Java function or util class which does rounding this way: func(3/2)
Does something like this make any sense at all in Java? class A<T extends
Does the Java Compiler optimize a statement like this if (a == true) {
What does this statement, Closing a ByteArrayOutputStream has no effect ( http://java.sun.com/javase/6/docs/api/java/io/ByteArrayOutputStream.html#close() ) mean?
Can anyone tell me what exactly does this Java code do? SecureRandom random =
In Java is there a way to check the condition: Does this single character
Can somebody tell me what does this mean? I'm going trough Java book and

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.