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 171272 - [68cat] "Assign Return Value To New Variable" infers wildcard bounds that don't compile
Summary: [68cat] "Assign Return Value To New Variable" infers wildcard bounds that don...
Status: RESOLVED DUPLICATE of bug 258167
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 6.x
Hardware: PC Windows XP
: P4 blocker (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on: 262073
Blocks:
  Show dependency tree
 
Reported: 2009-09-01 16:50 UTC by matthies
Modified: 2016-05-17 08:45 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 2009-09-01 16:50:13 UTC
Example:

    <K, V> void f(Map<? extends K, ? extends V> map)
    {
        map.entrySet();
    }

"Assign Return Value To New Variable" results in:

    <K, V> void f(Map<? extends K, ? extends V> map)
    {
        Set<Entry<? extends K, ? extends V>> entrySet = map.entrySet();
    }

This doesn't compile (unfortunately). What would compile is:

    <K, V> void f(Map<? extends K, ? extends V> map)
    {
        Set<? extends Entry<? extends K, ? extends V>> entrySet = map.entrySet();
    }
Comment 1 matthies 2009-09-01 17:03:52 UTC
PS: The reason it doesn't compile is that if it would, then this

    <K, V> void f(Map<? extends K, ? extends V> map, Entry<? extends K, ? extends V> entry)
    {
        Set<Entry<? extends K, ? extends V>> entrySet = map.entrySet();
        entrySet.add(entry);
    }

    void g()
    {
        Map<String, String> strMap = ...;
        Map<Number, Number> numMap = ...;
        f(strMap, numMap.entrySet().iterator().next());
    }

would compile too (where K = V = Object), allowing to add any type of entry to any type of map.
(Yes, map.entrySet() doesn't actually support add(), but let's assume it did.)

So, this is not a compiler bug.
Comment 2 matthies 2009-10-27 23:40:01 UTC
Still reproducable in 6.8 Beta.
Comment 3 Svata Dedic 2016-05-16 13:48:36 UTC

*** This bug has been marked as a duplicate of bug 258167 ***