interface

compareTo() implementation problems

冷暖自知 提交于 2019-12-11 19:22:06
问题 Hi i'm having trouble implementing the compareTo method. I've looked for answers but nothing has been any help. I'm trying to fill a TreeSet with various sizes of circles. I need compareTo in my circle class to be able to store them this way. import java.util.*; import java.lang.*; abstract class Shape { private String name; //e.g."circlel", "rectangle3" Shape(String name0) { name = name0; } abstract double area (); // area of shape abstract double perim(); // length of perimeter of shape

Kotlin define interface for enum class values method

匆匆过客 提交于 2019-12-11 18:25:47
问题 if I define an enum class, let's say: enum class MyEnum { } I can do the following as enum class all have a values method: val values = MyEnum.values() Now I want my enum to implement an interface and have access to the values() method: enum class MyEnum : EnumInterface { } interface EnumInterface { fun values() : Array<T> fun doStuff() { this.values() } } This doesn't compile and I'm sure how to type the values method. Is it possible to define such interface? Thanks! 回答1: You were really

Anonymous class override vs passing an interface, for designing callbacks in Java

人盡茶涼 提交于 2019-12-11 18:23:39
问题 I'm aware of 3 different ways to do callback type functionality in Java, but I don't fully understand the pros/cons of each. Java APIs are rich with methods similar in nature to this: Button b = new Button(); b.setClickListener(<implements ClickListener>); I'm using "button" as a generic example, not to refer to any specific API. 1.) One way to use it is to have your class implement the interface and pass it as the argument. To handle multiple "buttons" you'd have to use whatever information

Optimization Strategies around Interface Calls in Java

不打扰是莪最后的温柔 提交于 2019-12-11 17:52:36
问题 I have an application that utilizes a Provider Pattern. The application utilizes the provider implementation by calling interfaces that are defined by the application. I'm currently researching ways I can optimize my application around interface calls. I can limit the complexity of my application to the following: I only need to load the implementation dynamically once on start-up I only need one provider implementation for a particular set of interfaces for an application instance at any one

X does not implement Y (… method has a pointer receiver)

断了今生、忘了曾经 提交于 2019-12-11 17:35:56
问题 There are already several Q&As on this " X does not implement Y (... method has a pointer receiver) " thing, but to me, they seems to be talking about different things, and not applying to my specific case. So, instead of making the question very specific, I'm making it broad and abstract -- Seems like there are several different cases that can make this error happen, can someone summary it up please? I.e., how to avoid the problem, and if it occurs, what are the possibilities? Thx. 回答1: This

Get right ip adress of pc with multiple network cards

主宰稳场 提交于 2019-12-11 17:13:47
问题 Hej All, I've an application that listens on a socket. The problem is that the pc has 2 network cards and is connected to the company netork and a plc network of course we have to listen/bind/... onto the IPAdress we got from the DHCP in the company network. But when we do this: System.Net.IPEndPoint(System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName).AddressList(0) We get the IP of the PLC network. Now we are looking for a way to find dynamically the right IPAdress. I got already the tip

One function implementing Generic and non-generic interface

扶醉桌前 提交于 2019-12-11 17:02:39
问题 Lets say I have a class, which implements a generic interface public interface IItem {} public interface IStuff<out TItem> where TItem : IItem { TItem FavoriteItem { get; } } public class MyStuff<TItem> : IStuff<TItem> where TItem : IItem { public TItem FavoriteItem { get { throw new NotImplementedException(); } } } I have also one non-generic interface public interface IFavoriteItem { IItem FavoriteItem { get; } } I'd like to make MyStuff class implement this IFavoriteItem interface. Since

C# Generic and override methods

♀尐吖头ヾ 提交于 2019-12-11 16:26:51
问题 I created a question and realized that it was due to some design error on my part. However, I do think that that concept can be useful and I would like to know how to solve an issue similar, if possible. I want to create an algorithm that adds up 2 numbers, be it string or int . I also want to be able to output everything in the console and would like to avoid code duplication. I create a generic interface that changes according to the model. Then a class that handles the addition of the two

Twitter4j interfaces and class structure

好久不见. 提交于 2019-12-11 16:22:10
问题 The twitter4j packages are not clear to me. For instance how would I retrieve 500 tweets containing a certain hashtag? How would I declare a user and get all their tweets in the past week? For example, I would like the following: User brit = new User("Britney Spears"); List<Tweet> britTweets = brit.getAllTweets(); //assuming this method exists My problem is I cannot instantiate a User since it is declared abstract! What I see so far is a bunch of interfaces with a set of great functions that

external interface

核能气质少年 提交于 2019-12-11 15:54:37
问题 I have a calc function in java script that takes three integer parameters, following is the AS3 code import flash.external.ExternalInterface; var para:Array = new Array(); send_btn.addEventListener(MouseEvent.CLICK, clickListener); function clickListener(eventObj:Object ):void { para.push(mean.text); para.push(std.text); para.push(points.text); trace("click > " + para); ExternalInterface.call("calc",para ); } is this the right way of doing it and how do i get back 3 arguments back from the