This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 180867 - "Assign Return Value To New Variable" ignores explicit type argument
Summary: "Assign Return Value To New Variable" ignores explicit type argument
Status: RESOLVED INVALID
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 6.x
Hardware: PC Windows XP
: P3 normal (vote)
Assignee: Jan Lahoda
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-02-17 14:07 UTC by matthies
Modified: 2010-02-19 08:18 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description matthies 2010-02-17 14:07:26 UTC
Example (import java.util.*):

    List raw = null;
    Collections.<String> unmodifiableList(raw);

"Assign Return Value To New Variable" on the second line results in:

    List unmodifiableList = Collections.<String> unmodifiableList(raw);

...although the result type here is List<String>.

The expected result would have been:

    List<String> unmodifiableList = Collections.<String> unmodifiableList(raw);
Comment 1 Jan Lahoda 2010-02-19 06:45:54 UTC
The result is strictly speaking, the result is correct. An unchecked conversion is needed for the method invocation, and in such a case the return type is always an erasure of the methods return type (JLS 15.12.2.6). The question is whether the IDE should produce the unerased return type, or not. The difference is that:
Collections.<String> unmodifiableList(raw).get(0).length();
will not compile, but:
List<String> unmodifiableList = Collections.<String> unmodifiableList(raw);
unmodifiableList.get(0).length();
will (and may throw unexpected ClassCastException in runtime).
Comment 2 matthies 2010-02-19 08:18:09 UTC
I see, I wasn't aware of that. The important thing to realize (I guess) is that the code compiles (with warnings) even if the type arguments don't match, as for example in:

    List<Integer> list = Collections.<String> unmodifiableList(raw);

The warning for 'raw' here covers the warning vor assigning a raw List to List<Integer>.

Resolving the issue as invalid.