question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Child class overrides lambda in parent class

See original GitHub issue
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

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
calvarez-ovcommented, Sep 13, 2016

I opened an issue in the retrolambda project: https://github.com/orfjackal/retrolambda/issues/109

I guess this one here may be closed.

0reactions
calvarez-ovcommented, Sep 13, 2016

I did some tests building the retrolambda project locally. It appears the bug appears in this commit: https://github.com/orfjackal/retrolambda/commit/bf932457e45817cdee07f34c8c2059db44848e03

I have not done any investigation to understand what part of that commit introduces the bug.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript - how to inherit class and override lambda method
This method is called from the base constructor, and needs access to instance properties, so it needs to be a lambda function, so...
Read more >
Child class overrides lambda in parent class #109 - GitHub
One solution is to convert the private instance method into a package-private static method, which won't be overridable by child classes. This ...
Read more >
How to get child property inside parent class, with lambda?
... prop in the base class, make it overridable and override it in each subclass to return the value that makes sense for...
Read more >
Method overriding in Python - The Digital Cat
In Python method overriding occurs simply defining in the child class a method with the same name of a method in the parent...
Read more >
Method Overriding in TypeScript - GeeksforGeeks
Example 1: In this example, we will declare two classes and inside the parent class we will declare one method which will be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found