Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 370680 - Assist user regarding generics
Summary: Assist user regarding generics
Status: NEW
Alias: None
Product: Xtend
Classification: Tools
Component: Backlog (show other bugs)
Version: 2.3.0   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-06 03:02 EST by Sven Efftinge CLA
Modified: 2012-11-08 05:02 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sven Efftinge CLA 2012-02-06 03:02:07 EST
A common mistake is to over-specify a type with type arguments.
For instance, in many cases only the upper bound is used and needed:

def List<String> toListOfNames(/* over-specified */List<Person> persons) {
  persons.map[name]
}

In the case above the parameter type should be List<? extends Person>. The consequence is that the function is not applicable to Lists of subtypes of Person.

One could give the user a warning and a quick fix if a type is over-specified, and is declared locally (i.e. overriding methods should be excluded).
Of course, it should be possible to deactivate this warning locally and globally.

I'm not totally convinced by this idea, but wanted to persist it and leave it open for further discussion. Anybody knows if CheckStyle, Netbeans or IntelliJ do this already?

One could generalize this warning, such that one also gets a warning if the used members are of a certain super type but a more specific subtype was declared. Although conceptually along the lines, I think this would be annoying.