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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:45:17+00:00 2026-05-11T07:45:17+00:00

In this question , TofuBeer was having problems creating a genericized IterableEnumeration . The

  • 0

In this question, TofuBeer was having problems creating a genericized IterableEnumeration.

The answer came from jcrossley3 pointing to this link http://www.javaspecialists.eu/archive/Issue107.html which pretty much solved the problem.

There is still one thing I don’t get. The real problem, as effectively pointed out by erickson, was that:

You cannot specify a wildcard when constructing a parameterized type

But removing the wildcard in the declaration didn’t work either:

final IterableEnumeration<ZipEntry> iteratable                    = new IterableEnumeration<ZipEntry>(zipFile.entries()); 

Results in the following error:

Main.java:19: cannot find symbol symbol  : constructor IterableEnumeration(java.util.Enumeration<capture#469 of ? extends java.util.zip.ZipEntry>) location: class IterableEnumeration<java.util.zip.ZipEntry>         final IterableEnumeration<ZipEntry> iteratable = new IterableEnumeration<ZipEntry>(  zipFile.entries());                                                          ^ 1 error 

But the samples in the JavaSpecialist do work:

  IterableEnumeration<String> ie =               new IterableEnumeration<String>(sv.elements()); 

The only difference I can spot is that in the JavaSpecialists blog, the Enumeration comes from a Vector whose signature is:

public Enumeration<E> elements() 

while the one that fails comes from ZipFile whose signature is:

public Enumeration<? extends ZipEntry> entries() 

Finally, all of this is absorbed by the for-each construct and the static make method suggested in the link

for(final ZipEntry entry : IterableEnumeration.make( zipFile.entries() ))  {     if(!(entry.isDirectory())) {         names.add(entry.getName());     } } 

But!! the point in that newsletter was not to solve this problem, but to avoid the need to specify a generic type, just because the syntax looks ugly!!

So.. my questions is:

What is happening?

Why doesn’t creating an instance of IterableEnumeration work when the parameter is an Enumeration whose type is <? extends SomeClass> ? And why does the make for-each construct swallow the problem?!!!

Why does this work:

for(final ZipEntry entry : IterableEnumeration.make( zipFile.entries() ))  { 

but this not work?

final IterableEnumeration<ZipEntry> iteratable                      = IterableEnumeration.make( zipFile.entries() ); 

Below is a (slightly) modified version of TofuBeer’s original code:

import java.util.Enumeration; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.Vector;  public class Main {     private ZipFile zipFile;      public Set<String> entries() {          final Vector<ZipEntry>    vector = new Vector<ZipEntry>();         // why this works.         //final IterableEnumeration<ZipEntry> iteratable = new IterableEnumeration<ZipEntry>( vector.elements() );          // but this do not.         //final IterableEnumeration<ZipEntry> iteratable = new IterableEnumeration<ZipEntry>( zipFile.entries() );          // nor this          final IterableEnumeration<ZipEntry> iteratable = IterableEnumeration.make( zipFile.entries() );          // And what's with the for-each that doesn't care about the type?             final Set<String>   names = new HashSet<String>();          for(final ZipEntry entry : IterableEnumeration.make( zipFile.entries() ))  {             if(!(entry.isDirectory())) {                 names.add(entry.getName());             }         }          return (names);     } }  class IterableEnumeration<T> implements Iterable<T> {     private final Enumeration<T> enumeration;      public IterableEnumeration(final Enumeration<T> e) {         enumeration = e;     }      public Iterator<T> iterator() {         return new Iterator<T>() {               public boolean hasNext() {                 return (enumeration.hasMoreElements());             }              public T next() {                 return (enumeration.nextElement());             }              public void remove() {                 throw new UnsupportedOperationException('Cannot remove via an Enumeration');             }         };     }     // As suggested by http://www.javaspecialists.eu/archive/Issue107.html     // but doesn't help with: final IterableEnumeration<ZipEntry> iteratable = IterableEnumeration.make( zipFile.entries() );     public static <T> Iterable<T> make(Enumeration<T> en) {         return new IterableEnumeration<T>(en);     } } 

I want to understand it!!

  • 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. 2026-05-11T07:45:18+00:00Added an answer on May 11, 2026 at 7:45 am

    I’m not sure what’s happening with the foreach loop, but you need to add the wildcard to your declaration of IterableEnumeration to accept the unspecified type returned from ZipFile.entries().

    Replace

        private final Enumeration<T> enumeration;      public IterableEnumeration(final Enumeration<T> e) {         enumeration = e;     }      public static <T> Iterable<T> make(Enumeration<T> en) {         return new IterableEnumeration<T>(en);     } 

    With

        private final Enumeration<? extends T> enumeration;      public IterableEnumeration(final Enumeration<? extends T> e) {         enumeration = e;     }      public static <T> Iterable<T> make(Enumeration<? extends T> en) {         return new IterableEnumeration<T>(en);     } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 93k
  • Answers 93k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer rm ./--remove-files. Note that -- isn't interpreted by the shell,… May 11, 2026 at 6:33 pm
  • Editorial Team
    Editorial Team added an answer https://developer.mozilla.org/en/Prism/Extensions Are you sure the MaxVersion is the problem? <em:maxVersion>1.0.0.*</em:maxVersion>… May 11, 2026 at 6:33 pm
  • Editorial Team
    Editorial Team added an answer You can enable double buffering for ListView by deriving from… May 11, 2026 at 6:33 pm

Related Questions

I'm using the Felix OSGi iPOJO library, and I'm programmatically accessing Factories to create
In this question the answer was to flip on a switch that is picked
In this question someone asked for ways to display disk usage in Linux. I'd
In this question , I was given a really cool answer to alternating an

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.