interface

Ambiguous call on an Action<T> where T inherits 2 interfaces having the same method signature

…衆ロ難τιáo~ 提交于 2019-12-25 04:59:20
问题 I have the following code: public class MyClass { public void MyMethod() { Action<Child> aFoo = a => a.Foo(); } } interface Parent1 { void Foo(); } interface Parent2 { void Foo(); } interface Child : Parent1, Parent2 { } However, the compiler tells me that I have an ambiguous call on aFoo . I tried to do Action<Child> aFoo = (A a) => a.Foo(); but it tells me that I cannot convert lambda expression to delegate type System.Action<Child> How do I resolve the error of ambiguity? 回答1: By casting

Using an interface from multiple async tasks

巧了我就是萌 提交于 2019-12-25 04:23:13
问题 I have an interesting fragment with multiple spinners. THe first spinner, loads the data into the second spinner based on what was selected. It looks something like this: When the fragment first loads the first spinner is "All" and it fills the listView with all the beers. Right now this is the only listView I can click on items without them force closing. The code for my portfolio is: public class Portfolio extends Fragment implements PortfolioGetAllBeers.OnArticleSelectedListener { String

Difference between Class reference and Interface reference

六月ゝ 毕业季﹏ 提交于 2019-12-25 04:22:36
问题 My code is: class Sample implements interf { public void intmethod(){ //some code.... } } public interface interf{ public void intmethod() } My question is what is difference between the following two statements Sample sam = new Sample(); interf int = new Sample(); 回答1: Let's say you have: class Sample implements interf { public void intmethod(){ //some code.... } public void sampleMethod() { // code only relevant to Sample objects} } class Sample2 implements interf { public void intmethod(){

Interface can not call self method

被刻印的时光 ゝ 提交于 2019-12-25 04:14:11
问题 I have defined two functions. When I pass a pointer to it, I can't get the defined method. Why is this? type Visitor interface { work() } func test(v *Visitor) { v.work() // error } func test1(v Visitor) { v.work() // ok } Error: v.work undefined (type *Visitor is pointer to interface, not interface) anyone know why, ths 回答1: func test(v *Visitor) { v.work() // error } v.work() ought to be a method call. But v is of type *Visitor , a pointer to interface. A pointer to interface has 0 methods,

Winforms UserControl is not using the inheritance tree I have created. What am I doing wrong

我怕爱的太早我们不能终老 提交于 2019-12-25 04:09:24
问题 I am working on a wizard form framework that will allow me easily create wizard forms. I have a WizardForm form that has a panel on it. My plan is to dynamically load UserControls into this panel on the form. Each UserControl that is loaded onto the form panel must implement certain properties (allowNavigateNext, AllowNAvigate previous etc.). So I have created an interface to enforce that contract so that any custom user control can be used in the wizard as long as it implements that

Returning a subclass type object instead of superclass type object as demanded by interface

北慕城南 提交于 2019-12-25 03:53:36
问题 I have a class called Node and another class called ClassicNode which extends Node. Now I have an interface AgentInterface implemented by ClassicNode class. The interface states that there must be a method Node selection(); As you can see, the return type should be of type Node. But in the class ClassicNode can I implement it like this instead:- ClassicNode selection(){ //Code } Will this satisfy the interface? (since ClassicNode inherits Node) 回答1: Yes; it's called covariant return . Note,

Interface from one fragment to another android

北城以北 提交于 2019-12-25 03:38:21
问题 I am facing a problem implementing an interface defined in one fragment and using it to another. I know I need to do this through activity but I have added fragments dynamically inside another fragment. Please look at the snapshot to understand more about my problem. . I have a fragment called ACTIVITY fragment inside which I load fragments dynamically. The Comments textview is clickable and when clicked it a CommentDialogFragment is shown. This dialog fragment is shared by all the fragments.

NullPointerException with Fragment Interface Listener

三世轮回 提交于 2019-12-25 03:25:16
问题 I'm sorry, I'm sure that this will be simple but I just cannot see where I'm going wrong here. I've got a Fragment (a tool list) that can start a number of other fragments (tools) in a two pane set up. There is an activity that sits above & I am using it to manage the removal of tool fragments when their 'close button' is pressed. It then pops a tool from the backstack if one exists. The strange thing is, that I have this working within one fragment but the 'cut & pasted' code into another

Is calling a superinterface's default method possible? [duplicate]

一曲冷凌霜 提交于 2019-12-25 02:47:14
问题 This question already has answers here : Explicitly calling a default method in Java (4 answers) Closed 5 years ago . Say I have two classes, A and B : class A { void method() { System.out.println("a.method"); } } class B extends A { @Override void method() { System.out.println("b.method"); } } After instantiating B as b , I can call B 's method like b.method() . I can also make B 's method call A 's method with super.method() . But what if A is an interface: interface A { default void method

XmlSerialization and interfaces

邮差的信 提交于 2019-12-25 01:49:07
问题 I know that you can't serialize/deserialize using an interface but I'm confused by behaviour I'm seeing. When I deserialize and cast back to the interface, some properties are null. But if I cast back to the concrete type the same property has a value? So, given this XML (shortened for brevity): <Page> <ComponentPresentations> <ComponentPresentation> <Component> <Categories> <Category> <Id>tcm:35-540-512</Id> Deserializing with var serializer = new XmlSerializer(typeof(Page)); page = (IPage