Bug 80526 - [1.5] Static method return type error conflicts with warning
Summary: [1.5] Static method return type error conflicts with warning
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M4   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-08 17:29 EST by Barry Kaplan CLA
Modified: 2004-12-09 08:45 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 Barry Kaplan CLA 2004-12-08 17:29:29 EST
Consider:

public class PrivateAccessor {

    public static <T> T get(Object object, String fieldName) {
        return getField(object, fieldName);
    }
}

In this case 'getField(...)' is indicated with the error "Type mismatch: cannot
convert from Object to T PrivateAccessor.java". 

If the code is changed to:

    public static <T> T get(Object object, String fieldName) {
        return (T) getField(object, fieldName);
    }

The '(T) getField(...)' is indicated with the warning "Unnessary cast from
Object to T".
Comment 1 Jerome Lanneluc CLA 2004-12-09 06:43:11 EST
Indeed Object is not compatible with the type parameter T. (T could be
substituted with String for example). javac has the same behavior.
Comment 2 Barry Kaplan CLA 2004-12-09 08:45:49 EST
But then why the warning indicating the unecessary cast? My point was that it
should not /both/ be an error in one case and a warning in the other. No?