Why is the following code ok, but as soon as T is added to Main as a generic, it throws the following error?
'Main.this' cannot be referenced from a static context
//public class Main<T> { - uncomment this for the error to appear
public class Main {
public static void main(String[] args) {
new Main();
}
class TestNonStatic {}
private static class TestStatic {
public TestStatic(TestNonStatic nonStatic) { //this is the line that fails
}
}
}
I went through generics restrictions but I don't get it why this results into an error. I also went through a lot of similar questions but I don't understand why adding the generic would change the situation.