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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:32:14+00:00 2026-05-18T05:32:14+00:00

I have declared the following method: private void mockInvokeDBHandler(Map<String, Object>… rows) { List<Map<String, Object>>

  • 0

I have declared the following method:

private void mockInvokeDBHandler(Map<String, Object>... rows) {
    List<Map<String, Object>> allRows = Arrays.asList(rows));
    // rest of method omitted
}

It is invoked by clients using something like

Map<String, Object> row1 = new HashMap<String, Object>();
Map<String, Object> row2 = new HashMap<String, Object>();

mockInvokeDBHandler(row1, row2);

However, the last line shown above generates a warning

Type safety : A generic array of Map is created for a varargs parameter

I don’t fully understand this, but I guess it’s because varargs params are converted to arrays, and it’s a bad idea to have an array whose type is a generic class (because generics are invariant, whereas arrays aren’t).

I could resolve this problem by redifining the method as

private void mockInvokeDBHandler(List<Map<String, Object>> rows) {
}

But this places the burden of putting the row objects into a List on the client, which I’d rather avoid. Is there a better solution?

  • 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-18T05:32:14+00:00Added an answer on May 18, 2026 at 5:32 am

    To pass the arguments to a varargs method the compiler will place the arguments into an array.

    The warning is to let you know that the compiler cannot guarantee that each of the elements in the array – each of the arguments to the varags method – is truly a Map<String, Object>.

    This is a bit of an annoying warning because there is no way you can work around this, other than to redefine the method signature to not use varargs. IMO it is safe to ignore as long as you are pretty sure of the actual run-time types of these arguments (which in this case, you are).

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

Sidebar

Related Questions

I have a C# interface with certain method parameters declared as object types. However,
Consider an object declared in a method: public void foo() { final Object obj
I have the following enum declared: public enum TransactionTypeCode { Shipment = 'S', Receipt
I have a COM object written using the MS ATL library. I have declared
I have a c# object with a property called Gender which is declared as
I Have usercontrol and i registered the following javascript method in code behind :
I have the following web service method (.ASMX file): [WebMethod(EnableSession = true)] [ScriptMethod(ResponseFormat =
Let's say I have the following simple table variable: declare @databases table ( DatabaseID
In my C# source code I may have declared integers as: int i =
This is a contrived example, but lets say I have declared objects: CustomObj fooObj;

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.