interface

Java polymorphism - how to call same method in different classes

折月煮酒 提交于 2019-12-23 02:55:27
问题 So I'm making a game in java, and I have objects all with the 2 methods; update() and render() . In my main class, where the game loop resides, I have to call both the update() and render() methods for every object that is updatable and renderable. Is there any way to set up some form of interface where I can call the methods once and it will call it in all implemented objects? 回答1: The other answers are correct, however it would be much better to use the composite pattern: public interface

How do I use user defined Java classes within Matlab?

送分小仙女□ 提交于 2019-12-23 02:48:38
问题 I have read the documentation and several websites on exactly how to do this, however Matlab does not seem to pick up the classes that I have added to the dynamic java class path. Nor do I use the right syntax to correctly construct the object. I have an class HandDB and which to create an object of this type and invoke it's static methods to connect to a SQL database. The class has an empty constructor and takes no parameters. The class is part of a package 'nuffielddb' which I made in a

Sending in an object of type Object instead of String - Polymorphism

孤街浪徒 提交于 2019-12-23 02:47:26
问题 I've an existing method which looks like this: public void parseMessage(String message){ ... ... ... } and the method is called by calling it as shown below String message; parseMessage(message); I need to modify it for it to process a new type of message. The parser for the new type of message which is called from the parseMessage method expects some properties first before it can parse the message. What i am thinking of doing is passing the message as an object that looks like this public

C# not connecting to R using RDotNet

廉价感情. 提交于 2019-12-23 02:34:08
问题 I am trying to interface C# to R using RDotNet . The following code is wants R to calculate the sum of two numbers and C# to get the result back and display it in the command window. using System; using RDotNet; namespace rcon { class Program { static void Main(string[] args) { string dllPath = @"C:\Program Files\R\R-3.1.0\bin\i386"; REngine.SetDllDirectory(dllPath); REngine.CreateInstance("RDotNet"); //REngine engine = REngine.GetInstanceFromID("RDotNet"); using (REngine engine = REngine

Questions with different types of answer in NHibernate

本小妞迷上赌 提交于 2019-12-23 01:06:28
问题 I'm trying to find a tidy solution to a questionnaire problem. Let us say that I have a Questionnaire class which has a collection of Answer s, e.g. public class Questionnaire { public virtual ISet<Answer> Answers {get;set;} } Answers need to be of different types depending on the question, e.g. date of birth, marks out of ten, why do you think etc. My first thought was something like this: public class Question { public virtual QuestionType TypeOfQuestion {get;set;} public virtual string

java abstarct与Interface的区别

会有一股神秘感。 提交于 2019-12-22 19:20:28
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> abstract class和interface是Java语言中对于抽象类定义进行支持的两种机制,正是由于这两种机制的存在,才赋予了Java强大的面向对象能力。 abstract class和interface之间在对于抽象类定义的支持方面具有很大的相似性,甚至可以相互替换,因此很多开发者在进行抽象类定义时对于 abstract class和interface的选择显得比较随意。其实,两者之间还是有很大的区别的,对于它们的选择甚至反映出对于问题领域本质的理解、对于设计意图的理解是否正确、合理。本文将对它们之间的区别进行一番剖析,试图给开发者提供一个在二者之间进行选择的依据。 一、理解抽象类 abstract class和interface在Java语言中都是用来进行抽象类(本文中的抽象类并非从abstract class翻译而来,它表示的是一个抽象体,而abstract class为Java语言中用于定义抽象类的一种方法,请读者注意区分)定义的,那么什么是抽象类,使用抽象类能为我们带来什么好处呢?在面向对 象的概念中,我们知道所有的对象都是通过类来描绘的,但是反过来却不是这样。并不是所有的类都是用来描绘对象的,如果一个类中没有包含足够的信息来描绘一个具体的对象,这样的类就是抽象类

Access “this” pointer of concrete class from interface

不羁岁月 提交于 2019-12-22 19:13:08
问题 After writing a test, I determined that the this pointer in an interface is not equal to the this pointer of the concrete class, meaning I can't just use a C-style cast on it. class AbstractBase {...}; class AnInterface { public: AnInterface() {...} // need AbstractBase * here ~virtual AnInterface() {...} // and here }; class Concrete : public AbstractBase, public AnInterface {}; My interface needs a base class pointer to the concrete class inheriting it in the constructor and destructor in

TypeScript: generic interface as union of other interfaces

故事扮演 提交于 2019-12-22 18:48:32
问题 I would like to create a generic interface with properties that represent a union of properties from other interfaces. Let's say I have two interfaces interface A { something: string; somethingElse: number; } interface B { something: Array<string>; } I do not want to write interface C as interface C { something: string | Array<string>; somethingElse?: number; } because that would mean that whenever I modify either of the interfaces A or B , I would need to manually modify interface C as well.

AXI4 Streaming interface: how to manage Floating Point array in HLS for generating HW accelerators and connect them, safely, in an RTL project?

拥有回忆 提交于 2019-12-22 18:27:33
问题 In the end what I want to do is to use a streaming interface with single precision floating point arrays in Vivado Design Suite to build hardware accelerators. HLS User Guide UG902 shows that is possible to create HW accelerators (starting from C, C++, SystemC, OpenCL code) using different interfaces. If you want to use an AXI4 streaming interface, HLS synthesizes the signals TREADY and TVALID but it doesn't synthesize the signal TLAST necessary to connect the RTL interface generated to Zynq

Creating object from OnClickListener interface

不羁岁月 提交于 2019-12-22 18:26:46
问题 OnClickListener is an static interface but I am instantiating from OnClickListener. I'm confused and wondering that can we generate objects from interface in java? Why don't we create concrete class, inherit from OnClickListener interface? 回答1: That is what is known as an anonymous inner class . The Swing documentation for Java Standard Edition covers it here, and I imagine it's used for much the same purpose in Android development. It allows you to more simply hook up various event handler