Can I extend my Metaball class with theBlobDetection.Blob-Class?

edited December 2013 in Library Questions

I am trying to extend the Blob-class of v3ga blobDetection library but I get an error saying: implicit super constructor Blob() is undefined. must explicitly invoke another constructor

Calling super() in the constructor did not help because it says that class Blob does not have a constructor Blob(). Does anybody have experience in extending this class?

Answers

  • edited December 2013

    AFAIK, we aren't obliged to call parent class w/ super()? :-/

    class PV extends PVector {
      PV() {
        println("Hey!");
      }
    }
    
  • Answer ✓

    It is the case when a parent class defines a constructor with parameters, but not one without parameter.

    Then, a class extending it must explicitly call the super-constructor of its parent.

    Example:

    class Bob
    {
      String goo;
    
      Bob(String goo)
      {
        this.goo = goo;
      }
    }
    
    class SubBob extends Bob
    {
      int v;
    
      SubBob(String goo, int v)
      {
        this.v = v;
      }
    }
    
    void setup()
    {
      SubBob sb = new SubBob("x", 42);
      println(sb.v, sb.goo);
      exit();
    }
    

    You will get this error. Solutions: if you can, add a parameterless constructor to the parent class, if it makes sense (you cannot, here), or call super(goo); at the start of the sub-class' constructor.

  • Thanks for your comments. It worked out calling super(parent) while parent is the blobDetection-object

Sign In or Register to comment.