interface

Android: Listening for variable changes

旧城冷巷雨未停 提交于 2019-12-17 18:26:37
问题 I've been searching for a KISS example of how to do this, and while they all seem (and I've gone through them ALL!) simple enough, I still cannot get my head around the concept. I'm referring to custom listeners (ones that do not extend anything)... In particular, creating a listener for a boolean variable so that I can set off some methods when its value changes. this is an example of an example I've tried: android how to make listener to a custom variable? If someone has the time to explain

How to call an explicitly implemented interface-method on the base class

£可爱£侵袭症+ 提交于 2019-12-17 18:16:12
问题 I have a situation, where two classes (one deriving from the other) both implement the same interface explicitly: interface I { int M(); } class A : I { int I.M() { return 1; } } class B : A, I { int I.M() { return 2; } } From the derived class' implementation of I.M() , I'd like to call the implementation of the base class, but I don't see how to do it. What I tried so far is this (in class B): int I.M() { return (base as I).M() + 2; } // this gives a compile-time error //error CS0175: Use

How to use java.Set

你说的曾经没有我的故事 提交于 2019-12-17 18:08:56
问题 I'm trying to make it working for quite some time,but just can't seem to get it. I have object Tower built of Block's. I've already made it working using arrays, but I wanted to learn Set's. I'd like to get similar functionality to this: public class Tower { public Tower(){ } public Tower add(Block k1){ //(...) //if block already in tower, return "Block already in tower" } public Tower delete(Block k1){ //(...) //if block already dleted, show "No such block in tower" } } Someone gave me some

Overriding interface method return type with derived class in implementation

混江龙づ霸主 提交于 2019-12-17 17:56:12
问题 I am trying to implement (C#) an interface method in a class, returning a derived type instead of the base type as defined in the interface: interface IFactory { BaseCar GetCar(); } class MyFactory : IFactory { MyCar GetCar() { } } Where, of course: class MyCar : BaseCar { } However, the following error happens: 'MyFactory' does not implement interface member 'IFactory.GetCar()'. 'MyFactory.BaseCar()' cannot implement IFactory.GetCar()' because it does not have the matching return type of

Why is there no IArray(T) interface in .NET?

▼魔方 西西 提交于 2019-12-17 16:34:12
问题 Update 2011-Jan-06: Believe it or not, I went ahead and incorporated this interface into an open source library I've started, Tao.NET. I wrote a blog post explaining this library's IArray<T> interface, which not only addresses the issues I originally raised in this question (a year ago?!) but also provides a covariant indexed interface , something that's sorely lacking (in my opinion) in the BCL. Question (in short): I asked why .NET has IList<T> , which implements ICollection<T> and

Java interface extends Comparable

微笑、不失礼 提交于 2019-12-17 16:32:57
问题 I want to have an interface A parameterised by T A<T> , and also want every class that implements it to also implement Comparable (with T and its subtypes). It would seem natural to write interface A<T> extends Comparable<? extends T> , but that doesn't work. How should I do it then? 回答1: When Comparable<? extends T> appears it means you have an instance of Comparable that can be compared to one (unknown) subtype of T , not that it can be compared to any subtype of T. But you don't need that,

Performance difference between passing interface and class reloaded

本小妞迷上赌 提交于 2019-12-17 16:30:11
问题 There's a consensus that using interfaces is better than using classes. I surely agree: a library method accepting ArrayList instead of List would be a crap. There's also a consensus that the performance is always the same. Here my benchmark begs to differ. There are 1 to 4 implementations of both an interface and an abstract class. When more than two implementations get used, the performance starts to diverge. I'm looking for an explanation for this behavior (and also for the origin of the

C# casting an inherited Generic interface

有些话、适合烂在心里 提交于 2019-12-17 16:19:07
问题 I'm having some trouble getting my head around casting an interface I've come up with. It's an MVP design for C# Windows Forms. I have an IView class which I implement on my form classes. There's also an IPresenter which I derive into various specific Presenters. Each Presenter will manage the IView differently depending on the role, for example opening the dialog to enter a new set of data with an AddPresenter as opposed to editing existing data with an EditPresenter which would preload data

C# casting an inherited Generic interface

◇◆丶佛笑我妖孽 提交于 2019-12-17 16:18:16
问题 I'm having some trouble getting my head around casting an interface I've come up with. It's an MVP design for C# Windows Forms. I have an IView class which I implement on my form classes. There's also an IPresenter which I derive into various specific Presenters. Each Presenter will manage the IView differently depending on the role, for example opening the dialog to enter a new set of data with an AddPresenter as opposed to editing existing data with an EditPresenter which would preload data

Why can't I call methods within a class that explicitly implements an interface?

守給你的承諾、 提交于 2019-12-17 16:13:50
问题 Here's the story. I created an interface, IVehicle . I explicitly implemented the interface in my class, Vehicle.cs . Here is my interface: Interface IVehicle { int getWheel(); } here is my class: class Vehicle: IVehicle { public int IVehicle.getWheel() { return wheel; } public void printWheel() { Console.WriteLine(getWheel()); } } Notice that getWheel() is explicitly implemented. Now, when I try to call that method within my Vehicle class, I receive an error indicating that getWheel() does