Bug 515516 - Warn when method return type is a free type variable with no constraints from argument types
Summary: Warn when method return type is a free type variable with no constraints from...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.7   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-04-20 09:52 EDT by Stephan Herrmann CLA
Modified: 2020-06-05 18:36 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Herrmann CLA 2017-04-20 09:52:42 EDT
Methods of the style

   <T> T get()

are not safely implementable (other than returning null), because they promise to return whichever type the caller chooses, with no information available at the callee.

Candidate for an optional warning.


Parameterized return types like

  <T> List<T> emptyList()

are borderline, since with additional knowledge about the return value, it _may_ be safe to assume an arbitrary type argument (in particular when the instance does not support any methods mentioning T).

Mildly related: bug 58657.
Comment 1 Manoj N Palat CLA 2018-05-16 01:30:26 EDT
Bulk move out of 4.8