0
votes

I'm trying to work with java.util.ArrayList in a Java project in Eclipse. It resolves funny on this IDE, contrary to what I'm used to on NetBeans. For example:

On NetBeans, I can create a Generic ArrayList simply as follows:

List<Bundle> bundles = new ArrayList();

However, on Eclipse, this is the structure, if I'm to successfully declare and initialize an ArrayList:

List bundles = (List) new ArrayList<Bundle>();

I'm forced to do a type casting, and the Generisation can only be done on the right side.

This, however, is not too bad, untill I try to call call some of the ArrayList methods, such as bundles.add(bundle1);. I get an error highlight on the method add().

dundles. Ctrl+space gives me a 'No Default Proposals'

Have I got my IDE platform badly, or incompletely configured? What could be the problemo?

Thank you all in advance.

--- >

Eclipse Java EE IDE for Web Developers.
Version: Mars.1 Release (4.5.1)
Build id: 20150924-1200

--- >

java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) Client VM (build 25.60-b23, mixed mode)

2
Are you sure you've imported java.util.List and not some other kind of List ? - Titus
Yes. Completely sure @Titus. - Program-Me-Rev

2 Answers

0
votes

Try this:

List<Bundle> bundles = new ArrayList<>();
0
votes

Try:

    List<Bundle> bundles = new ArrayList<Bundle>();

This should be the syntactically correct way to do do it.

If this doesn't work, it may be an issue with Java. I believe that Java, at the runtime, contains information about the List's contents and components. So the List must know and have a component type when you create it.