Code Junkie
Code Junkie

Reputation: 7788

Generic collection looping through for loop

I'm having an issue looping through my generic collection. Although my class doesn't show any compiling errors directly, the IDE (Netbeans) is showing an error on the the class icon within the project tree saying "Error parsing file". Any help would be appreciated.

My code

public abstract class AutocompleteCacheImpl<E> implements AutocompleteCache {

    public void store(Collection<E> es) {
        for(E e : es) {
            store(e);
        }
    } 

    public void store(E e) {
        //do something
    }
}

interface

public interface AutocompleteCache<E> {

    public void store(Collection<E> es);

}

Upvotes: 0

Views: 89

Answers (2)

Sean Reilly
Sean Reilly

Reputation: 21836

public class AutocompleteCacheImpl<E> implements AutocompleteCache

This is wrong, because the AutocompleteCache interface is also generic.

Try this:

public abstract class AutocompleteCacheImpl<E> implements AutocompleteCache<E>

Also, the keyword public should come before the keyword abstract

Upvotes: 3

assylias
assylias

Reputation: 328598

You need to specify the generic type (AutocompleteCache ==> AutocompleteCache<E>) to let the compiler know that the E in AutocompleteCacheImpl is the same as the E in AutocompleteCache:

public abstract class AutocompleteCacheImpl<E> implements AutocompleteCache<E>

Upvotes: 2

Related Questions