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

  • Home
  • SEARCH
  • 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 3950552
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:37:29+00:00 2026-05-20T01:37:29+00:00

I found a ‘unusual’ generic syntax such as: Arrays.<String>asList(…); Collections.<String>emptyList(); Obviously, the results of

  • 0

I found a ‘unusual’ generic syntax such as:

Arrays.<String>asList(...);
Collections.<String>emptyList();

Obviously, the results of the methods are generic. Is such syntax for type checking? An Object array cannot be an argument to Arrays.<String>asList(...).

  • 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-20T01:37:30+00:00Added an answer on May 20, 2026 at 1:37 am

    <typearg>methodname is the syntax for explicitly specifying the type argument for a generic method

    When you use a generic class, you usually have to specify the type argument (e.g. String):

    ArrayList<String> list =  new ArrayList<String>();
    

    With a generic method, you don’t usually pass a type argument:

    public static <T> void foo(T param) {   }
    ...
    String s = ...;
    MyClass.foo(s);
    

    You’ll notice no where did we did the code explicitly specify we want the String version of foo, i.e. there was no explicit type argument <String> specified like we saw when using a generic class (List<String>).

    The compiler is doing some compiler magic to infer the generic type argument based on context. This is a great thing and very powerful.

    However, occassionally the compiler can’t infer the type arguments automatically:

    public static <T> void bar() { T myLocalVar = ...; ...  }
    MyClass.bar();
    

    What concrete version of bar are we trying to invoke, i.e. what is the type argument for this call? Well, the compiler doesn’t either. We have to explicitly state the type argument, just like we normally do when using a generic class:

    MyClass.<String>bar();
    

    Also see:

    • http://www.angelikalanger.com/GenericsFAQ/FAQSections/ParameterizedMethods.html#FAQ002
    • Lots of other good stuff there http://www.angelikalanger.com/GenericsFAQ/JavaGenericsFAQ.html

    Aside: it may be worth mentioning that the Java 7 will be adding the so-called diamond operator to allow us to have the compiler to infer the type arguments when using generic classes now too:

    ArrayList<String> list =  new ArrayList<String>();
    

    becomes

    ArrayList<String> list =  new ArrayList<>();
    

    What is the point of the diamond operator (<>) in Java 7?

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

Sidebar

Related Questions

Found out about this cool jQuery countdown which is initialized as such: <script type="text/javascript">
Found several other questions with this topic, but they were syntax errors of people
Found some old code, circa VS 2003. Now I have just VS 2008 (SP1)
Found the following in an Oracle-based application that we're migrating (generalized) : SELECT Table1.Category1,
Found this: Sub SurroundWithAppendTag() DTE.ActiveDocument.Selection.Text = .Append( + DTE.ActiveDocument.Selection.Text + ) End Sub But
found this regex: insert every 10 characters: $text = preg_replace(|(.{10})|u, \${1}. , $text); can
Found a piece of code today, that I find a little smelly... TMyObject.LoadFromFile(const filename:
Found this rather strange bug in IE8; element.style.top is limited to 1342177 pixels. Even
Found two libraries Rebex ( www.rebex.net ) and QuikSoft ( www.quiksoft.com ) any comments
I found this open-source library that I want to use in my Java application.

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.