I have the code below, where I am trying to extend a class, but the constructor has the following error:

"Shipment(Builder) is not public in Shipment; cannot be accessed from outside package."

None of the other answers on SO seem to apply or fix the problem. I'm grateful for any direction...

My subclass:

public class ShipmentSubclass extends Shipment {

public double foo; 

public ShipmentSubclass(Builder builder) {
  super(builder);
  this.foo = 0.0;
}

And Shipment is defined in another package (imported as a jar):

public class Shipment{

  public static class Builder {
    private String id;
    public Builder(String id) {
        this.id = id;
    }

    public Shipment build() {
        return new Shipment(this);
    }
  }

  private final String id;

  public Shipment(Builder builder) {
    this.id = builder.id;
  }
}
1

There are 1 best solutions below

0
On

After spending a few hours on this, I gave up [on Netbeans] and made a new project in Eclipse Neon. The same issue persisted with subclassing a class from a jar, but I added the source as a required project, the error went away, and I proceeded.