I am looking for a way to add a base class to a mosby MVPActivity. Let me explain what i need.
Usually when using mosby we would declare an activity like this:
public class LoginActivity extends MVPActivity<LoginView, LoginPresenter> {
//...
}
but i would like to add a base class so that i can do the calls like this:
public class LoginActivity extends BaseActivity<LoginView, LoginPresenter> {
//...
}
and then BaseActivity would be like this :
abstract class BaseActivity<T, P> extends MvpActivity<T extends MvpView, P> {
}
but this is not working as the IDE at compile time has an error saying that "extends MvpView" has unexpected bounds.
So how can i add a base class to a mosby MVPActivity ?
You have to apply the generic parameters with your extended class definition and define it with the extension.
abstract class BaseActivity<V extends MvpView, P extends MvpPresenter<V>>
extends MvpActivity<V, P> { }
Related
(This is a follow up to this question, which itself was a follow up to this question.)
I have the following interfaces/classes (skeleton code below)
interface Copyable<C extends Copyable<C>> {
interface Validator<V extends Validator<V>> extends Copyable<V> {
interface ValidateValue<O> extends Validator<ValidateValue<O>> {
abstract class AbstractValidator<V extends AbstractValidator<V>> implements Validator<V> {
class VVNull<O> extends AbstractValidator<VVNull<O>> implements ValidateValue<O> {
This used to work just grand when Copyable was implemented without the <C extends Copyable<C>> but, as the two previous questions make clear to me, Copyable really needs those generics.
Unfortunately, now I can't compile VVNull.
C:\java_code\CopyableCProblem.java:23: error: Validator cannot be inherited with different arguments: <ValidateValue<O>> and <VVNull<O>>
This is line 23 in the below source-code:
class VVNull<O> extends AbstractValidator<VVNull<O>> implements ValidateValue<O> {
VVNull<O> is a ValidateValue<O>. It passes itself up as a generic-parameter for goodness-sakes, and it implements ValidateValue<O>. The inheritance is completely linear--there's no "diamond" inheritance or anything, it's Copyable<--Validator<--ValidateValue<--VVNull.
I realize--or actually, I should say I think--that self-generics will work, that is, if you make every class self-genericized, such as
VVNull<O,V extends VVNull<O,V>>
but I am desperate to find another solution. Self-referential generics are a complete mess when you get down to sub-classes that need their own additional generics. That's why I only self-genericize through Validator, because it's the least-likely candidate to be directly used. ValidateValue and VVNull are frequently and directly used. I really really hope that there are other possibilites.
Comparable works just fine without requiring self-generics in all its implementing classes, so how can I make this work for Copyable?
Thank you for any advice.
public class CopyableCProblem {
}
interface Copyable<C extends Copyable<C>> {
C getObjectCopy();
}
interface Validator<V extends Validator<V>> extends Copyable<V> {
}
interface ValidateValue<O> extends Validator<ValidateValue<O>> {
#Override
ValidateValue<O> getObjectCopy();
boolean isValid(O o_o);
}
abstract class AbstractValidator<V extends AbstractValidator<V>> implements Validator<V> {
}
class VVNull<O> extends AbstractValidator<VVNull<O>> implements ValidateValue<O> {
#Override
public VVNull<O> getObjectCopy() {
return this;
}
public boolean isValid(O o_o) {
return (o_o != null);
}
}
Is this possible?
class A<T extends Service<E extends Entity>>
It's because I want to get the type of Service and Entity. Or any other way around to do it?
Currently I have an abstract method that sets the Service but if I can do it in parameter then much better.
I'm also wondering how can I pass the parameters in a base class:
I have ClassA that extends SubBaseClass1 that extends BaseClass1.
So:
class SubBaseClass1<E extends Entity, P extends Service<E>> { }
In BaseClass, I want to know the type of P and E.
Another question, if I have a method getBaseClass from another class, how will I specify the return type?:
public BaseClass<E extends Entity, T extends Service<E>> getBaseClass() { }
Is not working.
Found the answer:
public BaseClass<? extends IEntity, ? extends Service<?>> getBaseClass() { }
You would declare that like this:
class A<E extends Entity, T extends Service<E>>
Then you could have, for example:
A<Foo, Bar> a;
... where Foo is a subclass of Entity and Bar is a subclass of Service<Foo>.
I want to create a composite in GWT that require a class which extends a class and implements an interface. Psudo code as below (it does not work apparently):
class GridRow<T extends Widget implements HasText> extends Composite{
//more codes here
}
That's written as:
class GridRow<T extends Widget & HasText> extends Composite {
// ...
}
You can have [class or interface]( & [interface])* (in pseudo regex language).
I have Scala class and I would like to extend one of the generic classes of JavaFX to create my custom contro
public abstract class SkinBase <C extends Control, B extends BehaviorBase <C>>
extends StackPane
implements Skin <C>
but I can't. example:
import javafx.scene.control.Control
class MyControl extends Control {
}
import com.sun.javafx.scene.control.skin.SkinBase
class MyControlSkin extends SkinBase[MyControl,MyControlBehavior] {
}
import com.sun.javafx.scene.control.behavior.BehaviorBase
class MyControlBehavior extends BehaviorBase[MyControl] {
}
Any suggestions how can I do that?
This works for me:
class MyControlBehavior(myControl: MyControl) extends BehaviorBase[MyControl](myControl)
I have a class that extends generic class that also extends (another) generic class.
class B<TypeB> extends C{}
class C<TypeC>{}
and now my problems is how to specify the TypeC when creating class A
should be something like:
class A extends B<Type1><C<Type2>>
but the above actually does not compile.
Your decl of B should be:
class B<TB, TC> extends C<TC> {
}
and your target will be
class A extends B<ConcreteB, ConcreteC> {
}