interface

How do I cast Class FooObject to class BarObject which both implement interface IObject? [duplicate]

落花浮王杯 提交于 2019-12-21 19:41:13
问题 This question already has answers here : Casting between two types derived from the (same) interface (9 answers) Casting between classes that share the same interface (7 answers) Casting a interface derived class to another derived class (1 answer) Closed 10 months ago . I have 2 classes which implement the same interface. But somehow I cannot cast them from one to another. Here's an example: public interface IObject { // ... } public class FooObject : IObject { // ... } public class

Accessing the java Object class methods using an interface reference

我们两清 提交于 2019-12-21 19:41:09
问题 Let's consider the following example. public interface SimpleInterface { public void simpleMethod(); } public class SimpleClass implements SimpleInterface{ public static void main(String[] args) { SimpleInterface iRef = new SimpleClass(); SimpleClass cRef = new SimpleClass(); iRef.simpleMethod(); // Allowed. Calling methods defined in interface via interface reference. cRef.specificMethod(); // Allowed. Calling class specific method via class reference. iRef.specificMethod(); // Not allowed.

Is there a way with Java Generics to take Generic parameter that requires implementation of 2 interfaces?

别说谁变了你拦得住时间么 提交于 2019-12-21 18:29:55
问题 Say I have this code - public interface ParentInterface1 { public List<? extends ChildInterface1> getChildren(); public void setChildren(List<? extends ChildInterface1> children); } public interface ParentInterface2 { public List<? extends ChildInterface2> getChildren(); public void setChildren(List<? extends ChildInterface2> children); } public interface ChildInterface1 { public String getField(); public void setField(String field); } public interface ChildInterface2 { public String getField

Java graph library for visualising flowchart-like diagrams

牧云@^-^@ 提交于 2019-12-21 17:56:10
问题 I'm in the process of making an interface for drawing flow chart like diagrams (essentially circuit diagrams) that contain nodes that look like the following: +-------+ in1 -->| |---> out1 | | in2 -->| | | | in3 -->| |---> out2 +-------+ i.e. each box has several input edges and several output edges. For visual clarity, it makes more sense if all the input edges are grouped on one side and all the output edges are grouped on the other. The interface will involve the user connecting the input

Setting An Interface{} Parameter By Reference

僤鯓⒐⒋嵵緔 提交于 2019-12-21 12:30:42
问题 I am having difficulty understanding how to set an interface value that has been passed as a pointer. I am trying to accomplish something along the lines of this: import "fmt" var Stuff map[string]interface{} func main() { var num int Stuff["key"] = 9001 get("key", &num) fmt.Println("num:", num) } func get(k string, v interface{}) { *v = Stuff[k] } What would I have to do to make my program output be num: 9001 Edit: is there a possible catch-all solution using reflect ? 回答1: You can emulate

Is anyone implementing an interface for Eureqa in R?

穿精又带淫゛_ 提交于 2019-12-21 12:28:39
问题 Ok this question is not exactly technical but very pertinent and current. If you may have not heard Eureqa (http://creativemachines.cornell.edu/eureqa) is a machine learning (?) based tool that helps you find hidden equations and mathematical relationships within the data. It does sound futuristic and experimental and to a great degree it seems it is. This is the relevant talk by Eureqa inventor Hod Lipson http://www.youtube.com/watch?v=Xja6sLl6dVg entitled Mining experimental data. So i

Angular 2 interface for service

强颜欢笑 提交于 2019-12-21 12:09:30
问题 I want to developpe a search component. Here is the use case: This component calls a service with search's terms parameters. The service call the api endpoint and returns the resulting objects as a collection. The component display the results in the template. I want to write only one search component able to call different service depending on the case. Imagine I have two service: SearchInMaleEmployeeService SearchInFemaleEmployeeService Both of these services implements a search function

What are the differences between implementation of Interfaces in Delphi and Lazarus (FPC)?

血红的双手。 提交于 2019-12-21 12:05:09
问题 We have a project full of custom components that today is working in Lazarus and Delphi. I'm thinking in code interfaces on it, but I am not much familiar with them. What I would like to know is: What are the implementation nuances from Delphi and Lazarus interfaces? There is something that I should be specially aware? Will I have to code really different things? Background explanation: I think the components could benefit from interfaces, or at least, I will learn more from them. For example

Supporting both covariance and contravariance for a single type parameter [duplicate]

∥☆過路亽.° 提交于 2019-12-21 11:23:12
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Covariance and Contravariance on the same type argument You can declare a generic type parameter as covariant by using the out keyword: interface ICovariant<out R> You can declare a generic type parameter as contravariant by using the in keyword: interface IContravariant<in R> And you can also support both for different type parameters: interface IVariant<out R, in A> So why can't you suport both for a single

Class inheriting from several Interfaces having same method signature

余生长醉 提交于 2019-12-21 10:20:06
问题 Say, I have three interfaces: public interface I1 { void XYZ(); } public interface I2 { void XYZ(); } public interface I3 { void XYZ(); } A class inheriting from these three interfaces: class ABC: I1,I2, I3 { // method definitions } Questions: If I implement like this: class ABC: I1,I2, I3 { public void XYZ() { MessageBox.Show("WOW"); } } It compiles well and runs well too! Does it mean this single method implementation is sufficient for inheriting all the three Interfaces? How can I