interface

How to access derived class members from an interface?

流过昼夜 提交于 2020-08-19 05:43:36
问题 I have three classes; Stamp, Letter and Parcel that implement an interface IProduct and they also have some of their own functionality. public interface IProduct { string Name { get; } int Quantity { get; set; } float Amount { get; } } public class Stamp : IProduct { public string Name { get { return "Stamp"; } } public int Quantity { get; set; } public float Amount { get; set; } public float UnitPrice { get; set; } } public class Letter : IProduct { public string Name { get { return "Letter"

How to access derived class members from an interface?

时光怂恿深爱的人放手 提交于 2020-08-19 05:42:45
问题 I have three classes; Stamp, Letter and Parcel that implement an interface IProduct and they also have some of their own functionality. public interface IProduct { string Name { get; } int Quantity { get; set; } float Amount { get; } } public class Stamp : IProduct { public string Name { get { return "Stamp"; } } public int Quantity { get; set; } public float Amount { get; set; } public float UnitPrice { get; set; } } public class Letter : IProduct { public string Name { get { return "Letter"

How do i dereference a pointer value passed as the empty interface?

空扰寡人 提交于 2020-08-05 05:28:48
问题 I've got a method taking a target interface{} on a type that I use for database access like: func (c *client) Query(query someType, target interface{}) error { return c.db.Query(query).Decode(target) } This is then called like result := resultType{} if err := c.Query(myQuery, &result); err == nil { // do sth with result } Which does what I want it do as I am passing the pointer address of result The trouble I am now running into is that I do not know how I can mock this kind of behavior

what is a static interface in java?

纵饮孤独 提交于 2020-07-30 04:20:33
问题 I was reading through the Map.Entry interface, when I noticed it is a 'static' interface. I didn't quite understand what a static interface is, and how is it different from a regular interface ? public static interface Map.Entry<K,V> This is the definition of the interface. Docs here: http://docs.oracle.com/javase/6/docs/api/java/util/Map.Entry.html 回答1: I'm curious about the case when it's not an inner interface. The static modifier is only allowed on a nested classes or interfaces. In your

what is a static interface in java?

拟墨画扇 提交于 2020-07-30 04:20:22
问题 I was reading through the Map.Entry interface, when I noticed it is a 'static' interface. I didn't quite understand what a static interface is, and how is it different from a regular interface ? public static interface Map.Entry<K,V> This is the definition of the interface. Docs here: http://docs.oracle.com/javase/6/docs/api/java/util/Map.Entry.html 回答1: I'm curious about the case when it's not an inner interface. The static modifier is only allowed on a nested classes or interfaces. In your

Why does example code access deleted memory in IUnknown?

时光总嘲笑我的痴心妄想 提交于 2020-07-23 04:56:24
问题 Quite a number of examples when using interfaces such as IUnknown , in this example IDocHostUIHandler but it doesn't really matter - use code similar to this: class TDocHostUIHandlerImpl : public IDocHostUIHandler { private: ULONG RefCount; public: TDocHostUIHandlerImpl():RefCount(0){ } // IUnknown Method HRESULT __stdcall QueryInterface(REFIID riid, void **ppv) { if (IsEqualIID(riid,IID_IUnknown)) { *ppv = static_cast<IUnknown*>(this); return S_OK; } else if (IsEqualIID(riid, IID

Why does example code access deleted memory in IUnknown?

匆匆过客 提交于 2020-07-23 04:56:08
问题 Quite a number of examples when using interfaces such as IUnknown , in this example IDocHostUIHandler but it doesn't really matter - use code similar to this: class TDocHostUIHandlerImpl : public IDocHostUIHandler { private: ULONG RefCount; public: TDocHostUIHandlerImpl():RefCount(0){ } // IUnknown Method HRESULT __stdcall QueryInterface(REFIID riid, void **ppv) { if (IsEqualIID(riid,IID_IUnknown)) { *ppv = static_cast<IUnknown*>(this); return S_OK; } else if (IsEqualIID(riid, IID

Why does example code access deleted memory in IUnknown?

Deadly 提交于 2020-07-23 04:54:07
问题 Quite a number of examples when using interfaces such as IUnknown , in this example IDocHostUIHandler but it doesn't really matter - use code similar to this: class TDocHostUIHandlerImpl : public IDocHostUIHandler { private: ULONG RefCount; public: TDocHostUIHandlerImpl():RefCount(0){ } // IUnknown Method HRESULT __stdcall QueryInterface(REFIID riid, void **ppv) { if (IsEqualIID(riid,IID_IUnknown)) { *ppv = static_cast<IUnknown*>(this); return S_OK; } else if (IsEqualIID(riid, IID

why java can run with a compile time error in eclipse

末鹿安然 提交于 2020-07-20 17:28:48
问题 interface A { public void f(); public void g(); } class B implements A { public void f() { System.out.println("B.f()"); } } public class Main { public static void main(String[] args) { B tmp = new B(); tmp.f(); System.out.println("B.f()"); } } I don't implement all the method in the interface A in B and it has a error that The type B must implement the inherited abstract method A.g() but why it can get the output that B.f() B.f() 回答1: Eclipse can "patch" around certain classes of compile

Static Method in Interface with Generic signature

笑着哭i 提交于 2020-07-17 10:20:16
问题 As of Java 8 you can have default or static methods implemented in Interfaces as the below public interface DbValuesEnumIface<ID, T extends Enum<T>> { T fromId(ID id); ID getId(); static String getDescriptionKey(){ return "this is a test"; } } I would like to declare the above with the static method having a signature that uses bounds defined by the implementing classes since the method's implementation should be the same for all,with the only thing different should be the generics declared,