interface

Scaleable Fluent Interface with Inheritance

别等时光非礼了梦想. 提交于 2019-12-14 04:14:03
问题 I am trying to write a Fluent Interface API that can scale well. What structure would allow for strong types, inheritance, and state-full(as in the class type)? For instance class A { public A PerformFoo() { //do stuff return this; } } class B : A { } I would like class B when calling PerformFoo to return B not A, ideally I would prefer to stay away from public class B : A { public new B PerformFoo() { return (B)base.PerformFoo(); } } As to not have to override or new Every method in child

subclass of thread implementing Runnable interface

▼魔方 西西 提交于 2019-12-14 03:53:30
问题 It confuses me why a subclass of thread that implements a runnable interface doesn't force me to override the run method. Basically, when i create simple class that implements Runnable it forces me to override the run method. But when i made the ordinary class a subclass of thread, it didn't force me to override the class anymore. What's the logic behind this? 回答1: When a non-abstract class declares that it implements an interface, what that means is that the class must have a concrete

Explicitly calling a default method in Java

懵懂的女人 提交于 2019-12-14 03:53:23
问题 Java 8 introduces default methods to provide the ability to extend interfaces without the need to modify existing implementations. I wonder if it's possible to explicitly invoke the default implementation of a method when that method has been overridden or is not available because of conflicting default implementations in different interfaces. interface A { default void foo() { System.out.println("A.foo"); } } class B implements A { @Override public void foo() { System.out.println("B.foo"); }

AspectJ Pointcut call on JAX-RS annotated Interface method

北慕城南 提交于 2019-12-14 03:17:14
问题 I'm trying to intercept a method of an interface annoted with a JAX-RS @POST. My Pointcut works for all non-interface methods and if the @POST-Annotation is directly at the called method. The interface method to intercept: @POST Response postToConnector(@Context CallContext callContext, String contentStream) throws Exception; The Pointcut to match the method: @Pointcut("call(@(javax.ws.rs.DELETE || javax.ws.rs.GET || javax.ws.rs.HEAD || javax.ws.rs.OPTIONS || " + "javax.ws.rs.POST || javax.ws

Casting generic type with interface constraint

佐手、 提交于 2019-12-14 03:15:16
问题 I have the following classes and interfaces public interface IFoo {} public class Foo : IFoo {} public interface IWrapper<T> where T : IFoo {} public class Wrapper<Foo> : IWrapper<Foo> {} How can I cast Wrapper<Foo> to IWrapper<IFoo> ? An exception is raised when using Cast (InvalidCastException) as I get null when using as. Thanks for the help! UPDATE Here is a more concrete example: public interface IUser {} public class User : IUser {} public interface IUserRepository<T> where T : IUser {}

Extract interfaces from a class

会有一股神秘感。 提交于 2019-12-14 03:13:51
问题 I want to generate interface from my model class in eclipse/intelij generating from single class is quite easy Right click --> Refactor --> generate interface but the problem is i have 100's of classes. is there any tool/plugin or script which can generate multiple interface in 1 go from a single package. or any maven plugin to do so. http://mojo.codehaus.org/gwt-maven-plugin/generateAsync-mojo.html here i got a plugin but it generate generateAsync 回答1: Probably fastest way is write own

How can I return the values from the interface methods into a JSON object?

限于喜欢 提交于 2019-12-14 03:08:09
问题 I want to return a C# class as a JSON object: This is my code of my switch: public IDatasource GetDataSource(DataSourceType type) { switch (type) { case DataSourceType.CONTROL: return new ControlDS(); case DataSourceType.RISK: return new RiskDS(); case DataSourceType.MOI: return new MoiDS(); case DataSourceType.LOSSEVENTS: return new LossEventDS(); case DataSourceType.KRI: return new KriDS(); default: throw new ArgumentOutOfRangeException(); } } For each type it must return a whole class. Let

Proper way to get a generics type argument

社会主义新天地 提交于 2019-12-14 03:07:29
问题 The following code gets the first type parameter class declared generically in the interface SomeGenericInterface which gets concretely implemented in the class SomeClass . This code actually works. The question is: Does it work in any case, i.e. are the following two Class methods: getInterfaces() getGenericInterfaces() guaranteed to always have the same number of elements with the same respective order of the interfaces returned by these methods? Or is there some safer way to do this? <!--

Java: Implementation of Interface with Methods passing Interface parameter

社会主义新天地 提交于 2019-12-14 02:38:59
问题 I have a given interface called IAbc, which consists of a method with a parameter of interface IXyz. I am not sure whether I should create an attribute IXyz or an attribute XyzImpl in my implementation of IAbc. public interface IXyz { } public class XyzImpl implements IXyz { public void doSomething() { ... } } public interface IAbc { public void setXyz(IXyz val); public IXyz getXyz(); } Implementation 1: public class AbcImpl1 implements IAbc { private XyzImpl attr; public void setXyz(IXyz val

import class in different directory

核能气质少年 提交于 2019-12-14 02:33:32
问题 Actually, I am trying to finish this practice in "Think in Java" for self-learning purpose -- Exercise 6: (2) Create an interface with at least one method, in its own package. Create a class in a separate package. Add a protected inner class that implements the interface. In a third package, inherit from your class and, inside a method, return an object of the protected inner class, upcasting to the interface during the return. so I created a class named IgetResult.java under directory "a"