jeudi 10 décembre 2015

How to get something like `MyClass

I am trying to create a custom ArgumentExtractor in Ninjaframework, in which I have to create a class that implements ninja.params.ArgumentExtractor<T> which has method public Class<T> getExtractedType()

import java.util.Optional;
class OptionalParamExtractor implements ArgumentExtractor<Optional<String>> {
    ...
    @Override
    public Class<Optional<String>> getExtractedType() {
        return Optional<String>.class; // Compiler don't let me do this.
    }
}

At the line return Optional<String>.class;, I got a syntax error. How can I properly return the object of type Class<Optional<String>> in this case? I tried

    @Override
    public Class<Optional<String>> getExtractedType() {
        return Optional.of("").getClass();
    }

But did not work, I got an error Type mismatch: cannot convert from Class<capture#1-of ? extends Optional> to Class<Optional<String>>





Aucun commentaire:

Enregistrer un commentaire