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 - Initialize uninitialized interface-typed variables with an instance of some implementation (Set, Map, etc)
Summary: Initialize uninitialized interface-typed variables with an instance of some i...
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Refactoring (show other bugs)
Version: 8.2
Hardware: All All
: P3 normal with 1 vote (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-12-20 00:43 UTC by pekarna
Modified: 2016-12-20 00:43 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 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.