Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 370680

Summary: Assist user regarding generics
Product: [Tools] Xtend Reporter: Sven Efftinge <sven.efftinge>
Component: BacklogAssignee: Project Inbox <xtend-inbox>
Status: NEW --- QA Contact:
Severity: enhancement    
Priority: P3    
Version: 2.3.0   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

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.