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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:25:24+00:00 2026-06-09T19:25:24+00:00

From Sun Tutorials for generics Type Inference To illustrate this last point, in the

  • 0

From Sun Tutorials for generics

Type Inference

To illustrate this last point, in the following example, inference
determines that the second argument being passed to the pick method is
of type String:

static <T> T pick(T a1, T a2) { return a2; }  
Serializable s = pick("d", new ArrayList<String>());

Origirally I thought that the idea is that you could use any parameter in place of T as long as it ends up with String. Example ArrayList<ArrayList<String>>

But then I saw that the following also compiled fine:
Serializable s = pick("d", new ArrayList<Integer>());
It seems that T is inferred to be a Serializable and not a String?

So what is the meaning of the statement

inference determines that the second argument being passed to the pick
method is of type String

  • 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-09T19:25:25+00:00Added an answer on June 9, 2026 at 7:25 pm

    In this case, the 3 types are Serializable, String, ArrayList<String>.

    • Serializable does not extend anything
    • String implements Serializable and other unrelated stuff
    • ArrayList<String> implements Serializable and other unrelated stuff

    So the most specific type that applies to all 3 is Serializable.

    If you replace the call with Serializable s = pick("d", new Object()); for example, it does not compile any longer because the most specific type is now Object and you can’t cast Object to Serializable.

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

Sidebar

Related Questions

This is the basic printing program example from the Sun tutorial : PrinterJob job
Here's an excerpt from Sun's Java tutorials : A switch works with the byte
I want to rewrite in scala the example from Sun's tutorial about concurrency in
From the Scala API , I got the following example, which does not compile;
I'm learning about deadlocks in Java, and there's this sample code from Sun's official
I was following instructions from a Java website ( http://java.sun.com/docs/books/tutorial/essential/io/file.html#createStream ) on creating or
I am following this tutorial for sending Emails from My App. When i try
I've just try Jasper Report, I'm following tutorial from this site Also I downloaded
Below is code directly from the Sun tutorials describing Deadlock. I however don't understand
From Sun's Java Tutorial , I would have thought this code would convert a

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.