Aizen Aizen - 2 years ago 75
Java Question

C# vs JAVA instance of Interface

I am not sure how am I suppose to go about my question. It is about Android can Instantiate Interface. I am trying to do in C#. Now I am pretty sure that the rules for both Java and C# is you can't create an Instance of abstract and Interface as being said.

But I would really like to know how Android does this practice.

In Android you can do this.

public interface Checkme{
void Test();
void Test2();

public void myFunc(Checkme my){
//do something

// Now this is the actual usage.

public void Start(){

myFunc(new Checkme(){
public void Test()

public void Test2()



Actually once you press Enter on
new Checkme()
You will automatically get the Override methods of the Interface. Like auto Implement method of an Interface in C#.

I hope my question make sense.

Answer Source

C# doesn't support anonymously auto-implemented interfaces because it has delegates:

public void Foo(Func<string> func) {}

// call it somewhere:
instance.Foo(() => "hello world");

With delegates you can fill the gap and it can be even more powerful than implementing interfaces with anonymous classes.

Learn more about delegates.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download