I am trying to create a static method that returns a Generic Object of the same class which the static method is a member of but there is compilation error on the return type as
Cannot make a static reference to the non-static type T
Looking at other solutions on stack overflow I found this (Generics)Cannot make a static reference to the non-static type T
where a responder has provided an answer which says that for static methods, we must also include the target type before the return type but even this does not work
public class Condition<T extends Node> {
private boolean isInitialized=false;
private ConditionType type;
private NodeType nodeType;
private String propertyName;
private Predicate<T> onlyIfTest;
private Predicate<T> predicates;
private Condition() {
}
//Here at the return type i get the error Cannot make static...
public static Condition<T> include(NodeType type,String propertyName) {
Condition<T> condition = new Condition<T>(); //and an error here too
condition.type = ConditionType.INCLUDE;
condition.nodeType = type;
condition.propertyName = propertyName;
condition.isInitialized =true;
return condition;
}
The error that i get is Cannot make a static reference to the non-static type T. How can i make it work with a static method.