Skip to content

Child class overrides lambda in parent class #207

@cpalasanu

Description

@cpalasanu
public abstract class ParentActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getContentView());
        findViewById(R.id.button_parent).setOnClickListener(view -> Toast.makeText(this, "Parent onClick", Toast.LENGTH_LONG).show());
    }

    public abstract int getContentView();
}
public class MainActivity extends ParentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        findViewById(R.id.button_child).setOnClickListener(view -> Toast.makeText(this, "Child onClick", Toast.LENGTH_LONG).show());
    }

    @Override
    public int getContentView() {
        return R.layout.activity_main;
    }
}

Clicking on button_parent shows a Toast with "Child onClick"

test app: https://github.com/cpalasanu/RetrolambdaTest

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions