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

Summary: [68cat] "Assign Return Value To New Variable" infers wildcard bounds that don't compile
Product: java Reporter: matthies <matthies>
Component: HintsAssignee: Svata Dedic <sdedic>
Status: RESOLVED DUPLICATE    
Severity: blocker    
Priority: P4    
Version: 6.x   
Hardware: PC   
OS: Windows XP   
Issue Type: DEFECT Exception Reporter:
Bug Depends on: 262073    
Bug Blocks:    

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 ***