Automatically insert angle brackets when completing a generic type.

Please forgive me, if this question has already been aswered. It seems so trivial to me that I'm sure someone else already had the same idea.

In IntelliJ IDEA 12, is it possible to have the angle brackets (<>) be automatically inserted when a generic type is chosen from the auto-complete popup? Suppose I type "iter", and then open the completion popup, which contains the entry "Iterable<T> (java.lang)". I select that entry and "iter" is replaced by "Iterable". I often forget to insert the type paramters in declarations and only notice it a while later, which is annoying. If the completion popup would insert "Iterable<>" instead and put the cursor between the brackts, I would definitely not miss it.

Is that feature already there and can be enabled by configuration?

Thanks
Michael

1
2 comments

There's no such possibility, sorry. Sometimes one needs to use raw types, and inserting angle brackets always would require to delete them in such cases. There's also a possibility that you'll write ".InnerClassName" instead of generics.

There's an inspection called "Raw use of parameterized class", you can enable it and then you won't forget the type parameters.

If there's a selection in the completion list, you can also choose the Iterable item by typing "<" which would then also be inserted to the editor and you can add the type arguments right away.

1

The case where I want to use a raw type is very rare so deleting the angle brackets in these cases would not be an issue. But the trick with choosing the completion entry with the "<" key seems to be exactly what I was looking for. Thanks!

0

Please sign in to leave a comment.