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 269398

Summary: Initialize uninitialized interface-typed variables with an instance of some implementation (Set, Map, etc)
Product: java Reporter: pekarna <pekarna>
Component: RefactoringAssignee: Svata Dedic <sdedic>
Status: NEW ---    
Severity: normal    
Priority: P3    
Version: 8.2   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:

Description pekarna 2016-12-20 00:43:22 UTC
Let's have this code

    Set<String> names;
    modelTypes.add("Ada");

NetBeans will correctly mark that as uninitialized variable.

But a hint to "initialize variable" will just do

    Set<String> names = null;
    modelTypes.add("Ada");

My suggestion is that for some interfaces from java.util, NetBeans could initialize with the (assumably) most commonly used implementations, e.g.:

    Set<String> names = new HashSet<>();
    modelTypes.add("Ada");

Rationale:

1) Not often people initialize collections to null.
2) Typing the new ... manually is longer than overwriting with "null", should anyone need it.

Thanks for consideration.