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 253042 - Replace Constructor with Factory restricts access to constructor although it is used as method reference
Summary: Replace Constructor with Factory restricts access to constructor although it ...
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Refactoring (show other bugs)
Version: 8.0.2
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Ralph Ruijs
URL:
Keywords:
Depends on: 253232
Blocks:
  Show dependency tree
 
Reported: 2015-06-17 12:34 UTC by Jachym_Vojtek
Modified: 2015-06-29 09:25 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 Jachym_Vojtek 2015-06-17 12:34:28 UTC
Select constructor A(String)->Replace Constructor with Factory...
Factory Method Name: create

package pck;

interface I {
    A newTest(String s);
}

public class A {
    String s;

    public A() {
        this("Hi!");
    }

    public A(String s) {
        this.s = s;
    }

    public static void main(String[] args) {
        new A("Hello World!").saySomething();
    }

    public void saySomething() {
        System.out.println(s);
    }    
}

--

package pck;

public class B {

    void createTestAndSaySomething(I interf) {
        A t = interf.newTest("Hello World!");
        t.saySomething();

    }

    void test() {
        createTestAndSaySomething(A::new);
    }
}

The A(String) constructor is made private without any warning, in that case it will not be accessible from class B.test()