Error with super (this) when invoking a constructor in Java

5

Is this allowed?

public Produto(Context context) {
    super(context, this);   
}

You're giving me an error:

  

Can not refer to 'this' nor 'super' while explicitly invoking a constructor

I'm trying to make a simple MVC for when I type produto.Save() I can redeem the values that have been set below:

Produto produto1 = new Produto(this);
    produto1.setId(1);
    produto1.setNome("CELULAR");
    produto1.setPreco(5.5);
    produto1.Save();

The source of this is in this other question: Android getDeclaredFields value

    
asked by anonymous 01.04.2014 / 16:20

1 answer

4

It is not necessary (nor allowed) to pass a reference to the object itself in its constructor.

To refer to itself in the superclass, just use this , just like in the subclass.

No matter what level of the class hierarchy you are coding, this will always refer to the instance that was created.

    
01.04.2014 / 16:37