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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:34:39+00:00 2026-06-08T00:34:39+00:00

Given the following not-very-useful code: package com.something; import java.util.ArrayList; import java.util.Collection; //Not a generic

  • 0

Given the following not-very-useful code:

package com.something;

import java.util.ArrayList;
import java.util.Collection;

//Not a generic class!
public class Test {

  public <T> void plain(T param1, T param2) {}
  public <T> void fancy(T param1, Collection<T> param2) {}

  public void testMethod() {

    //No error
    fancy("", new ArrayList<String>());

    //Compiler error here!
    fancy("", new ArrayList<Integer>());

    //No error
    plain("", new ArrayList<Integer>());

  }

}

(Please correct my understanding if it’s wrong!)

The 2nd call to fancy() is a compiler error because Java can’t infer any common type between the two arguments (can’t infer Object since the second parameter must be a Collection.)

The call to plain() is not a compiler error because Java infers the common type of Object between the two arguments.

I recently came across code that had a method signature similar to plain().

My question is this:

Is plain()‘s signature useful for anything?

Perhaps the person who wrote that code thought that plain()‘s signature would enforce that both parameters have the same type at compile time, which is obviously not the case.

Is there any difference from or benefit to writing a method with a signature like plain() rather than just defining both parameters to be Objects?

  • 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-08T00:34:40+00:00Added an answer on June 8, 2026 at 12:34 am

    While the compiler does not infer the generic type one might intend, it will enforce type constraints that are explicitly specified. The following invocation results in a type error.

    this.<String>plain("", new ArrayList<Integer>()); /* Compiler error. */
    

    The parameterized method <String>plain(String, String) of type Test is not applicable for the arguments (String, ArrayList<Integer>)

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

Sidebar

Related Questions

I have found some very useful code: RewriteEngine On RewriteCond %{HTTP_HOST} ^www.example.com$ [NC] RewriteRule
Given the following data/schema: DECLARE @t1 TABLE ( Id int NOT NULL ) DECLARE
I have the following SQL query I was given, but I am not sure
The following code does not give a warning with g++ 4.1.1 and -Wall .
I have a dendrogram given to me as images. Since it is not very
Why does the following not give an error? for (int i=0; i<10; ++i) //
Sorry I am not familar with Python... It gives me the following error message
I use the following Javascript function.It will not work.It will give the Undefined Error
I have the following stack trace from valgrind. But it does not give me
// given following array: $data = array( 0=>array( data=>object1, col=>array( 0=>array( data=>object2, col=>array( 0=>array(

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.