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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:36:23+00:00 2026-06-14T03:36:23+00:00

What is reason behind supporting the syntax below on java 1.7 List<Integer> ints=new ArrayList<>();

  • 0

What is reason behind supporting the syntax below on java 1.7

List<Integer> ints=new ArrayList<>();

What flexibility does it provide?
If we wanted ints to be of a different type we would explicitly cast it and it would throw an error if the conversion could not be performed.

I am also not clear on how exactly does this work.Since List is an interface how are we able to call a method on it

List<Integer> ints = Arrays.asList(1,2);
ints.get(1);

Since return type of asList() is static<T> List<T> it’s okay to access a field of a static interface without any class providing an implementation of it.But how are we able to access a method on such an interface
The collections library has a lot of them like Collections.Sort()
Who provides the implementation of these methods?

  • 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-14T03:36:24+00:00Added an answer on June 14, 2026 at 3:36 am

    Question 1

    Using

    List<Integer> ints=new ArrayList<>();
    

    instead of

    List<Integer> ints=new ArrayList<Integer>();
    

    doesn’t add any flexibility as they’re exactly equivalent. The diamond (<>) indicates that we don’t want the raw type but the obvious parameterized type.

    Oracle describes it here :

    In Java SE 7, you can substitute the parameterized type of the
    constructor with an empty set of type parameters (<>):

    It just makes the code a little less verbose, thus easier to read and maintain. This is probably more evident on Oracle’s example :

    Map<String, List<String>> myMap = new HashMap<>();
    

    compared to

    Map<String, List<String>> myMap = new HashMap<String, List<String>>();
    

    Question 2

    Arrays.asList(1,2); returns an object from a concrete class implementing the List interface.

    In Java 1.6, it’s an instance of the fixed-size java.util.Arrays.ArrayList :

    3354    public static <T> List<T> asList(T... a) {
    3355        return new ArrayList<T>(a);
    3356    }
    

    but the important point is that an object always is of a concrete class implementing the methods its interfaces defines.

    When you’re doing Collections.sort(, you’re not using the Collection interface but the Collections class which contains this very concrete code :

    132     public static <T extends Comparable<? super T>> void sort(List<T> list) {
    133         Object[] a = list.toArray();
    134         Arrays.sort(a);
    135         ListIterator<T> i = list.listIterator();
    136         for (int j=0; j<a.length; j++) {
    137             i.next();
    138             i.set((T)a[j]);
    139         }
    140     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to identify the reason behind constants in Java I have learned
Does anyone know, what is the actual reason behind dollar variable notation in some
What can be the general reason behind the error below: Error executing child request
Anyone can tell me what's the reason behind this run-time error? java.lang.RuntimeException: Unable to
What is the logic/reason behind making String s= new String(Hello World); Illegal in C#?
List.AddRange() exists, but IList.AddRange() doesn't. This strikes me as odd. What's the reason behind
Is there any reason behind using date(January 1st, 1970) as default standard for time
The Question actually says it all. The reason behind this question is I am
As apparent in the title, I'm questioning the reason behind defining the macros inside
Can somebody explain what is the exact reason behind using Action<T> and Predicate<T> as

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.