Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implemented classes / subclasses in content assist in eclipse

What I'm trying to do is this:

List<String> list = new 

and then hit Ctrl+Space and get ArrayList<String>() (among others) to show up in the type proposal.

I thought I had this working previously, but I recently had to reinstall and can't find the setting for it.

This is Eclipse Java EE helios, but I can upgrade to indigo if need be.

I tried looking here for help, but didn't find the info I was looking for. I've tried checking all of the boxes under "Default Proposal Kinds" (Java -> Editor -> Content Assist -> Advanced" to no avail.

like image 705
Kevin McCarpenter Avatar asked Oct 18 '11 15:10

Kevin McCarpenter


3 Answers

Eclipse doesn't know which class implement the interface, and will not load them for all interfaces it has. BUT, Eclipse can learn what you use and show it to you on next use, maybe that's what happened to you, with time you taught Eclipse the implemented classes!

Here's an example of Eclipse before learning/and after learning what classes implement Map.

enter image description here

As you can see in the image, the first time, Eclipse didn't know anything other than HashMap, which I used before.

After that, I used TreeMap and LinkedHashMap by typing them manually (first time only) and Eclipse now cached them.

As the guys suggested, you can put the point on Map and click Ctrl+T it will give all the classes the implements this. Will be helpful the first time.

UPDATE in 2014!

As @K.Carpenter noticed, this feature is disabled in newer Eclipse versions. To re-enable it. Go to Window->Preferences->Java->Editor->Content Assist->Advanced.

Under Default Proposal Kinds, you will need to check Java Type Proposals

like image 174
medopal Avatar answered Nov 15 '22 17:11

medopal


Code like this is one of my pet hates of Java Generics. I use Google's Guava libraries to make my generics code more readable, and as a side-effect don't need this particular feature in Eclipse (though I agree it should be implemented). Guava has similar support for Sets too.

For example, I would normally declare my code as follows:

import com.google.common.collect.Lists;
...
List myList<String> = Lists.newArrayList();
like image 27
ifx Avatar answered Nov 15 '22 18:11

ifx


I would like to see Eclipse doing this, but I guess that the content assist never worked without a start character (unless there is some hidden feature we don't know).

Well, having this in mind, what I do to workaround from 'getting locked with the most used implementations' is to look at the javadoc in the All Known Implementing Classes section, to see other possibilities that I could use.

I know it is not an in-Eclipse solution, but it may help some users that got stuck in the same problem.

like image 45
falsarella Avatar answered Nov 15 '22 19:11

falsarella