Here's what I'm thinking. So lets say I have a class called intro and I want to do something when it starts and finishes. I'm wondering how could I do something like this:
开发者_开发技巧public Main(){
//Calls the object that overrides its own methods
new Intro(){
@Override
public void onStartIntro(){
}
@Override
public void onFinishIntro(){
}
}
What would need to happen in the Intro class to enable something like this?
just create an abstract class to force overriding of the methods (but a non-abstract class with non-final methods will also do)
abstract class Intro
{
abstract void onStartIntro();
abstract void onFinishIntro();
}
Maybe Something like this:
public class Main(){
public Main(){
new Intro();
}
private class Intro extends SomeOtherClass{
@Override
public void onStartIntro(){ /*...Code...*/ }
@Override
public void onFinishIntro(){ /*...Code...*/ }
}
}
Intro would only be available inside your "Main" class...
精彩评论