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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:36:44+00:00 2026-05-15T05:36:44+00:00

While coding a Map<>, I found out that declaring Map<int, int> is a syntax

  • 0

While coding a Map<>, I found out that declaring Map<int, int> is a syntax error while Map<Integer, Integer> is OK.

Is it only possible in Java to instantiate generics over object types, as opposed to primitives? If so, is there a noticeable performance penalty for boxing/unboxing of primitives?

  • 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-15T05:36:44+00:00Added an answer on May 15, 2026 at 5:36 am

    Yes, you can only use reference types for generic type parameters, and yes, there will be some performance penalty due to boxing/unboxing (which can be done automatically for the most part).

    Here’s a quote from the Java Generics FAQs:

    Are primitive types permitted as type arguments?

    No. Only reference types can be used as type arguments.
    A parameterized type such as List<int> or Set<short> is illegal. Only reference types can be used for instantiation of generic types and methods. Instead of List<int> we must declare a List<Integer>, using the corresponding wrapper type as the type argument.

    […] Note, that the lack of primitive type instantiations incurs a performance penalty. Autoboxing and -unboxing make the use of wrapper type instantiations of generic types very convenient and concise in the source code. But the concise notation hides the fact that behind the curtain the virtual machine creates and uses lots of wrapper objects, each of which must be allocated and later garbage collected. The higher performance of direct use of primitive type values cannot be achieved with generic types. Only a regular type can provide the optimal performance of using primitive type values.

    If you absolutely need the performance, Trove has many data structures specialized for primitive types, but for most practical purposes, using boxed primitive types with Java Collections Framework classes should yield more than acceptable performance.

    See also

    • Effective Java 2nd Edition, Item 49: Prefer primitive types to boxed types
    • Java Language Guide/Autoboxing
    • Java Language Guide/Generics
    • Java Tutorials/Generics
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 502k
  • Answers 502k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer $('.vpslink').click(function(e) { var id= $(this).attr('id'); alert('you clicked on id '… May 16, 2026 at 2:43 pm
  • Editorial Team
    Editorial Team added an answer Even if the method is public, Spring can't intercept method… May 16, 2026 at 2:43 pm
  • Editorial Team
    Editorial Team added an answer I'll address this specific function: bool probe() { #ifdef TARGET_OS_MAC… May 16, 2026 at 2:43 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

In Objective-C on Apple there is something called Key-Value Coding that allows you to
While deploying a dwr web app, i'm continuously getting this error. I dont know
Edit: This makes alot more sense to me now that i've taken a step
I've been spoilt with C# coding the last few years and now I'm back
While there is no One True Correct Style, some points of general agreement exist
Currently my workflow with Emacs when I am coding in C or C++ involves
im trying to implement some behaviors when a mapview element scrolls... by coding a
While trying problem 41 from the Euler Project, I ran across what seems to
I have been researching for a while and have actually created a prototype ASP.NET
An error occurred at line: 9 in the jsp file: /Test1.jsp The method addURL(String,

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.