interface

NumberFormatException when parsing String to Float value [duplicate]

喜欢而已 提交于 2019-12-24 19:29:52
问题 This question already has answers here : How to do an Integer.parseInt() for a decimal number? (9 answers) Closed last year . System.out.println("Enter a number: "); String in1 = input.nextLine(); Integer input1 = Integer.valueOf(in1); Float input2 = Float.parseFloat(in1); Double input3 = Double.valueOf(in1).doubleValue(); System.out.println(); System.out.println("Enter another number: "); String in2 = input.nextLine(); Integer input21 = Integer.valueOf(in2); Float input22 = Float.parseFloat

Java generic interface implementation: Compiler complains that one method does not override interface method, but is okay with the other methods

不打扰是莪最后的温柔 提交于 2019-12-24 18:09:59
问题 I have a builder interface: @ParametersAreNonnullByDefault public interface ILoadableBuilder<C extends ILoadable,T extends ILoadableBean> { public @Nonnull T getState(); public @Nonnull <B extends ILoadableBuilder<C,T>> B setComponentClass(final Class<C> componentClass); public @Nonnull <B extends ILoadableBuilder<C,T>> B setDriver(final WebDriver driver); public @Nonnull <B extends ILoadableBuilder<C,T>> B setLoadTimeoutInSeconds(final @Nonnegative int loadTimeoutInSeconds); public @Nonnull

Java generic interface implementation: Compiler complains that one method does not override interface method, but is okay with the other methods

家住魔仙堡 提交于 2019-12-24 18:08:13
问题 I have a builder interface: @ParametersAreNonnullByDefault public interface ILoadableBuilder<C extends ILoadable,T extends ILoadableBean> { public @Nonnull T getState(); public @Nonnull <B extends ILoadableBuilder<C,T>> B setComponentClass(final Class<C> componentClass); public @Nonnull <B extends ILoadableBuilder<C,T>> B setDriver(final WebDriver driver); public @Nonnull <B extends ILoadableBuilder<C,T>> B setLoadTimeoutInSeconds(final @Nonnegative int loadTimeoutInSeconds); public @Nonnull

call Activity when click button on core game LibGDX

谁说我不能喝 提交于 2019-12-24 17:56:52
问题 I have a button on Core game. I want when i click button, a Activity will run. I think i can use Interface but it do not work. buttonPost.addListener(new ClickListener(){ @Override public void clicked(InputEvent event, float x, float y) { myGameCallback.startActivity(); } }); Here is my interface public interface MyGameCallback{ public void startActivity(); } private MyGameCallback myGameCallback; public void setMyGameCallback(MyGameCallback callback){ myGameCallback=callback; } And android

call Activity when click button on core game LibGDX

只愿长相守 提交于 2019-12-24 17:56:05
问题 I have a button on Core game. I want when i click button, a Activity will run. I think i can use Interface but it do not work. buttonPost.addListener(new ClickListener(){ @Override public void clicked(InputEvent event, float x, float y) { myGameCallback.startActivity(); } }); Here is my interface public interface MyGameCallback{ public void startActivity(); } private MyGameCallback myGameCallback; public void setMyGameCallback(MyGameCallback callback){ myGameCallback=callback; } And android

Avoiding type checking when interface method parameters are abstract

主宰稳场 提交于 2019-12-24 16:54:29
问题 My interface looks like this: public interface UserHandler { CheckUsernameResponse CheckUsername(CheckUsernameRequest request); } The request and response types in the signature are abstract classes, giving a usage of something like: var fooHandler = new FooUserHandler(); var fooResponse = fooHandler.CheckUsername( new FooRequest { id = 1, FooProperty = "abc" }); or var barHandler = new BarUserHandler(); var barResponse = barHandler.CheckUserName( new BarRequest { id = 2, BarProperty = true }

Conflict between event in base class and implementation of interface event in derived class

て烟熏妆下的殇ゞ 提交于 2019-12-24 15:53:20
问题 Base class: Public MustInherit Class Connector Public Event Changed as EventHandler End Class Interface: Public Interface IPlug Event Changed as EventHandler End Interface Derived class: Public Class OutputConnector Inherits Connector Implements IPlug Event Changed as EventHandler Implements IPlug.Changed End Class VB.Net Problem: The Changed event in OutputConnector conflicts with the Changed event in Connector , of course. But I have to implement it to satisfy the IPlug interface. How can I

How do I retrieve a reference to a subobject using Reflection in C#?

南楼画角 提交于 2019-12-24 13:35:32
问题 I'm trying to use duck typing using reflection in C#. I have an object of some random type and I want to find if it implements an interface with a specific name and if it does - retrieve a reference to that interface subobject so that I can later read (get) a property value via that interface. Effectively I need as using Reflection. The first part is easy var interfaceOfInterest = randomObject.GetType().GetInterface("Full.Interface.Name.Here"); which will either retrieve the interface

C# interface implementation with derived interface

戏子无情 提交于 2019-12-24 12:24:01
问题 In the following sample class "SomeClass" does not implement "ISomeInterface". Why can't I implement this by passing a more derived interface which does implement the base requirement. Whatever instance would be passed it would still implement the base, am I missing something? namespace Test { public interface IBaseInterface { void DoBaseStuff(); } public interface IChildInterface : IBaseInterface { void DoChildStuff(); } public interface ISomeInterface { void DoSomething(IBaseInterface

Is type checking ever OK?

余生颓废 提交于 2019-12-24 12:23:08
问题 Is type checking considered bad practice even if you are checking against an interface? I understand that you should always program to an interface and not an implementation - is this what it means? For example, in PHP, is the following OK? if($class instanceof AnInterface) { // Do some code } Or is there a better way of altering the behaviour of code based on a class type? Edit : Just to be clear I am talking about checking whether a class implements an interface not just that it is an