I have a class. It will be simple container, which may contain some type T and type Optional<T> (guava Optional link)
With Container.of(T) there is no problems. But, how can create Container.ofOptional(T)?
Here is my class:
public final class Container<T>{
Class<?> firstClass;
Class<T> seconClass;
Container(Class<?> first, Class<T> second){
this.firstClass = first;
this.seconClass = second;
}
public static <T> Container<T> of(Class<?> first, Class<T> second){
return new Container(first, second);
}
public static <T> Container<Optional<T>> ofOptional(Class<?> first, Class<T> second){
return of(first, <what should I pass here>);
}
}
I tried Optional.of(second) but it doesn't work.
So, in result, I want method Container.ofOptional(T) return Container<Optional<T>>
Optional.of(second)isn't viable since you claim to be returning aContainer<Optional<T>>, and at best with that, you're returning anOptional<Class<T>>. I've been looking at this for a while now and I'm quite perplexed about its use case. Why are you just passing classes around instead of anything more concrete?return new Container(first, second);toofOptional, Java compiles correctly. But, what is your purpose? What you need to do withofOptional?Required Optional<T>, Found Optional