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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:35:02+00:00 2026-06-03T14:35:02+00:00

My code gives a warning in Java SE 7. How do I get around

  • 0

My code gives a warning in Java SE 7. How do I get around it without using annotations to suppress warnings; and with varargs as intended:

  import java.util.Iterator;

  public class UnionIterator < E > implements Iterator < E > {

  public static < E > Iterator < E > newInstance (Iterator < E > ... iterators) {
    return new UnionIterator < E >(iterators);
  }

  private Iterator < E > [] iterators;

  private UnionIterator (Iterator < E > ... iterators) {
    this.iterators = iterators;
  }

  @Override
  public boolean hasNext() {
    // TODO
    return false;
  }

  @Override
  public E next() {
    // TODO
    return null;
  }

  @Override
  public void remove() {
    // TODO
  }

}

Here is the warning:

$ javac UnionIterator.java 
Note: UnionIterator.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
$ javac -Xlint:unchecked UnionIterator.java 
UnionIterator.java:5: warning: [unchecked] Possible heap pollution from parameterized vararg type Iterator<E>
  public static < E > Iterator < E > newInstance (Iterator < E > ... iterators) {
                                                                     ^
  where E is a type-variable:
    E extends Object declared in method <E>newInstance(Iterator<E>...)
UnionIterator.java:11: warning: [unchecked] Possible heap pollution from parameterized vararg type Iterator<E>
  private UnionIterator (Iterator < E > ... iterators) {
                                            ^
  where E is a type-variable:
    E extends Object declared in class UnionIterator
2 warnings
  • 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-03T14:35:03+00:00Added an answer on June 3, 2026 at 2:35 pm

    You cannot. If you are using Java 7, you can use the @SafeVarargs annotation on the factory method to suppress the warning for every invocation of newInstance.

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

Sidebar

Related Questions

In my application I have written my own Logging utility using Java.Util.Logging import java.io.IOException;
I have the following code: import java.util.*; public class SellTransaction extends Transaction { private
when i am analyze my project following code gives me leakage warning. is there
The following code in VS2008 gives me a variable is already defined warning: if
I want the eclipse Java Compiler Warnings available as an ant task (ie without
I am using Fortify source code analyzer to analyze security issues in my Java
This code: class RawStringIterator { java.util.Stack<State> stateStack = new java.util.Stack<State>(); RawStringIterator(RawStringIterator i) { stateStack
The following code gives me the warning Contract class 'FooContracts' should be an abstract
This code gives me warnings: $ cat test.c #include<stdio.h> #include<time.h> int main() { time_t
I have the following code which gives the warning in the title. I am

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.