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 224992 - Add hint "Remove "<? extends XXX>" for final classes
Summary: Add hint "Remove "<? extends XXX>" for final classes
Status: RESOLVED WONTFIX
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 7.3
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Jan Lahoda
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-01-16 19:35 UTC by markiewb
Modified: 2013-01-16 20:14 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description markiewb 2013-01-16 19:35:08 UTC
ACTUAL: no hint, code is compilable - for example
<code>
    public <T extends String> T foo(){
        return null;
    }

    public Collection<? extends String> bar(){
        return null;
    }

    public void doBla(){
        List<? extends String> arrayListA = new ArrayList<String>();
        List<? extends Integer> arrayListB = new ArrayList<Integer>();
    }
</code>

EXPECTED: Provide hints to remove the unnecessary wildcard types. It is not possible to subclass final classes (f.e. String, Integer) - transformed example
<code>
    public String foo(){
        return null;
    }

    public Collection<String> bar(){
        return null;
    }

    public void doBla(){
        List<String> arrayListA = new ArrayList<String>();
        List<Integer> arrayListB = new ArrayList<Integer>();
    }
</code>
Comment 1 Jan Lahoda 2013-01-16 20:11:33 UTC
Sorry, but no.

The semantics of List<? extends String> is very different from List<String>: the first is "read-only", the latter is read-write. Compare e.g.:
List<? extends String> l1 = null;
List<String> l2 = null;

l1.add(""); //compilation error
l2.add(""); //OK

So using ? extends FinalType may generally be (and often is - otherwise, why the extra characters were typed?) intentional, and is generally neither safe not good to remove.
Comment 2 markiewb 2013-01-16 20:14:36 UTC
(In reply to comment #1)
> Sorry, but no.
> 
> The semantics of List<? extends String> is very different from List<String>:
> the first is "read-only", the latter is read-write. Compare e.g.:
> List<? extends String> l1 = null;
> List<String> l2 = null;
> 
> l1.add(""); //compilation error
> l2.add(""); //OK
> 
> So using ? extends FinalType may generally be (and often is - otherwise, why
> the extra characters were typed?) intentional, and is generally neither safe
> not good to remove.

You are right. Thanks for the clarification.