mercredi 5 avril 2017

Is it possible to create method with return type with question mark?

I am trying to implement an abstract class with generic fields without using generic class parameters. So, is it possible, for example, to create such classes:

public abstract class AbstractClass {

    public abstract Class<? extends SomeClass> getSomeClass();
    private Class<? extends SomeClass> myVariable = getSomeClass(); // what value will this variable contain? 
}

Second class:

public MyClass extends AbstractClass {

    @Override
    public InnerClass getSomeClass() {
        return InnerClass.class;
    }

    public static class InnerClass extends SomeClass {
        // some fields and methods here
    }
}

My main question is: will this approach work or not? If not, then please gave an advice how to implement this in another way.





Aucun commentaire:

Enregistrer un commentaire