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

Summary: Replace Constructor with Factory restricts access to constructor although it is used as method reference
Product: java Reporter: Jachym_Vojtek
Component: RefactoringAssignee: Ralph Ruijs <ralphbenjamin>
Status: NEW ---    
Severity: normal    
Priority: P3    
Version: 8.0.2   
Hardware: PC   
OS: Windows 7   
Issue Type: DEFECT Exception Reporter:
Bug Depends on: 253232    
Bug Blocks:    

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()