Java Generics: non-static type variable T cannot be referenced from a static context

auser :
interface A<T> {

    interface B {
       // Results in non-static type variable T cannot
       // be referenced from a static context
       T foo(); 
    }

}

Is there anyway round this? Why is T seen as static when referenced from A.B?

Jigar Joshi :

All member fields of an interface are by default public, static and final.

Since inner interface is static by default, you can't refer to T from static fields or methods.

Because T is actually associated with an instance of a class, if it were associated with a static field or method which is associated with class then it wouldn't make any sense

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

non-static class cannot be referenced from a static context

From Java

"Non-static variable this cannot be referenced from a static context" when creating an object

From Java

Why do I get "non-static variable this cannot be referenced from a static context"?

From Java

non static method cannot be referenced from a static context

From Java

"non-static variable this cannot be referenced from a static context"?

From Java

java : non-static variable cannot be referenced from a static context Error

From Java

Java - cannot be referenced from a static context

From Dev

java: non-static variable this cannot be referenced from a static context

From Dev

Rectangle.java:35: error: non-static variable this cannot be referenced from a static context

From Dev

Print at jTextArea using .setText returns error non-static variable cannot be referenced from static context

From Dev

error: non-static variable scan cannot be referenced from a static context in Java

From Dev

Non static variable cannot be referenced from static context java

From Dev

non-static variable this cannot be referenced from a static content Java

From Dev

non-static variable s cannot be referenced from a static context

From Dev

"Non-static method cannot be referenced from static context" error

From Dev

non static variable this cannot be referenced from a static context

From Dev

non-static variable cannot be referenced from a static context java

From Dev

non-static method getIntent() cannot be referenced from a static context

From Dev

Java JTextField and non-static variable cannot be referenced from a static context

From Dev

Non-static variable filepath cannot be referenced from a static context

From Dev

Java Language | Error :- non-static variable scan cannot be referenced from a static context

From Dev

Non-static edit() cannot be referenced from a static context

From Dev

non static setGravity cannot be referenced from static context

From Dev

Non-static variable cannot be referenced from a static context?

From Dev

non-static variable cannot be referenced from static context [JAVA]

From Dev

Error: Non-static variable super cannot be referenced from a static context >>but i use static keyword

From Dev

Java Blackjack program creates error: non-static variable this cannot be referenced from a static context

From Dev

Non-static method getSocketFactory cannot be referenced from a static context

From Dev

Can't call constructor of inner class in a static context -- "non-static variable this cannot be referenced from a static context"

Related Related

  1. 1

    non-static class cannot be referenced from a static context

  2. 2

    "Non-static variable this cannot be referenced from a static context" when creating an object

  3. 3

    Why do I get "non-static variable this cannot be referenced from a static context"?

  4. 4

    non static method cannot be referenced from a static context

  5. 5

    "non-static variable this cannot be referenced from a static context"?

  6. 6

    java : non-static variable cannot be referenced from a static context Error

  7. 7

    Java - cannot be referenced from a static context

  8. 8

    java: non-static variable this cannot be referenced from a static context

  9. 9

    Rectangle.java:35: error: non-static variable this cannot be referenced from a static context

  10. 10

    Print at jTextArea using .setText returns error non-static variable cannot be referenced from static context

  11. 11

    error: non-static variable scan cannot be referenced from a static context in Java

  12. 12

    Non static variable cannot be referenced from static context java

  13. 13

    non-static variable this cannot be referenced from a static content Java

  14. 14

    non-static variable s cannot be referenced from a static context

  15. 15

    "Non-static method cannot be referenced from static context" error

  16. 16

    non static variable this cannot be referenced from a static context

  17. 17

    non-static variable cannot be referenced from a static context java

  18. 18

    non-static method getIntent() cannot be referenced from a static context

  19. 19

    Java JTextField and non-static variable cannot be referenced from a static context

  20. 20

    Non-static variable filepath cannot be referenced from a static context

  21. 21

    Java Language | Error :- non-static variable scan cannot be referenced from a static context

  22. 22

    Non-static edit() cannot be referenced from a static context

  23. 23

    non static setGravity cannot be referenced from static context

  24. 24

    Non-static variable cannot be referenced from a static context?

  25. 25

    non-static variable cannot be referenced from static context [JAVA]

  26. 26

    Error: Non-static variable super cannot be referenced from a static context >>but i use static keyword

  27. 27

    Java Blackjack program creates error: non-static variable this cannot be referenced from a static context

  28. 28

    Non-static method getSocketFactory cannot be referenced from a static context

  29. 29

    Can't call constructor of inner class in a static context -- "non-static variable this cannot be referenced from a static context"

HotTag

Archive