interface

How to implement the same interface multiple times, but with different generics? [duplicate]

感情迁移 提交于 2020-07-15 00:30:19
问题 This question already has answers here : How to make a Java class that implements one interface with two generic types? (9 answers) Closed 6 years ago . I have the following interface, which I want to implement multiple times in my classes: public interface EventListener<T extends Event> { public void onEvent(T event); } Now, I want to be able to implement this interface in the following way: class Foo implements EventListener<LoginEvent>, EventListener<LogoutEvent> { @Override public void

How to implement the same interface multiple times, but with different generics? [duplicate]

妖精的绣舞 提交于 2020-07-15 00:30:14
问题 This question already has answers here : How to make a Java class that implements one interface with two generic types? (9 answers) Closed 6 years ago . I have the following interface, which I want to implement multiple times in my classes: public interface EventListener<T extends Event> { public void onEvent(T event); } Now, I want to be able to implement this interface in the following way: class Foo implements EventListener<LoginEvent>, EventListener<LogoutEvent> { @Override public void

How to implement the same interface multiple times, but with different generics? [duplicate]

北战南征 提交于 2020-07-15 00:26:03
问题 This question already has answers here : How to make a Java class that implements one interface with two generic types? (9 answers) Closed 6 years ago . I have the following interface, which I want to implement multiple times in my classes: public interface EventListener<T extends Event> { public void onEvent(T event); } Now, I want to be able to implement this interface in the following way: class Foo implements EventListener<LoginEvent>, EventListener<LogoutEvent> { @Override public void

Is const-casting away const-ness of references to actual const objects permitted if they are never modified through them?

喜你入骨 提交于 2020-07-01 06:56:56
问题 I have an abstract class that declares const and non-const member functions. For the sake of discussion let's say it looks like this: class record_interface { public: virtual ~record_interface() = default; virtual void set_foo(BoundedFloat) = 0; virtual BoundedFloat get_foo() const = 0; }; This is used as a high-level representation of a record that has different representations when saved to disc and transferred via the wire. So most implementations just need to convert their members to the

How to unmarshal JSON in to array of interface and use

徘徊边缘 提交于 2020-06-29 03:37:05
问题 I am having difficulty understanding how to correctly unmarshal some JSON data that goes in to an array of type inteface and then use it. I tried to make this example code as simple as possible to illustrate the problem I am having. The code can be found in the playground here: https://play.golang.org/p/U85J_lBJ7Zr The output looks like: [map[ObjectType:chair ID:1234 Brand:Blue Inc.] map[ID:5678 Location:Kitchen ObjectType:table]] { } false { } false Code package main import ( "fmt" "encoding

Is Interface comes in inheritance chain or not?

。_饼干妹妹 提交于 2020-06-26 06:54:36
问题 There are two type of statements on internet about Interface , that is Statement A Interfaces do not come in inheriting chain. other statement B Interfaces can inherit other interfaces These two are contradicting statements. Please tell me which one is right? 回答1: They are both true, sort of. Statement A: Interfaces don't strictly inherit. If you have a class that implements an interface, and you say base. You won't see members of the interface. Statement B: This would read better as

Struggling to See the Purpose of an Interface Type

拜拜、爱过 提交于 2020-06-17 08:33:37
问题 I've recently taken a liking to the Go programming language, I've found it wonderful so far but am really struggling to understand interfaces. I've read about quite a bit about them, but they still seem very abstract to me. I've wrote a quick bit of code that uses an interface below: package main import ( "fmt" "math" ) type Circer interface { Circ() float64 } type Square struct { side float64 } type Circle struct { diam, rad float64 } func (s *Square) Circ() float64 { return s.side * 4 }

Interface method with multiple return types

a 夏天 提交于 2020-05-30 07:16:49
问题 I'm struggling with interfaces. Consider this: type Generatorer interface { getValue() // which type should I put here ? } type StringGenerator struct { length int } type IntGenerator struct { min int max int } func (g StringGenerator) getValue() string { return "randomString" } func (g IntGenerator) getValue() int { return 1 } I want the getValue() function to return a string or an int , depending on if it's called from StringGenerator or IntGenerator When I try to compile this, I get

Interface method with multiple return types

不想你离开。 提交于 2020-05-30 07:14:19
问题 I'm struggling with interfaces. Consider this: type Generatorer interface { getValue() // which type should I put here ? } type StringGenerator struct { length int } type IntGenerator struct { min int max int } func (g StringGenerator) getValue() string { return "randomString" } func (g IntGenerator) getValue() int { return 1 } I want the getValue() function to return a string or an int , depending on if it's called from StringGenerator or IntGenerator When I try to compile this, I get

In Haxe, can you write a generic interface where a method type parameter is constrained by the class's type parameter?

♀尐吖头ヾ 提交于 2020-05-30 03:54:29
问题 I'm having trouble writing the generic interface below. In my class, I have a function that takes an array of < any type that extends a parent class > and traces its first element. Since I'm only reading elements from the array, I'm using it as if its a covariant compound type, and therefore I'm guaranteed to have the cast statement never fail. Now I want to abstract this out even more and write a interface that defines fn using another generic type T. I want fn to be able to accept any Array