You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AccessingInstanceFieldsStatically.java 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. public class AccessingInstanceFieldsStatically {
  2. public static void main(String[] args) {
  3. new AccessingInstanceFieldsStatically().realMain(args);
  4. }
  5. public void realMain(String[] args) {
  6. }
  7. }
  8. class T {
  9. public void printIt() {}
  10. public int getJ() { return -1; }
  11. public static void m() {
  12. Object o = this; //ERROR static reference to this
  13. this.clay++; //ERROR static reference to instance field
  14. clay++; //ERROR static reference to instance field
  15. printIt(); //ERROR static reference to instance method
  16. }
  17. public T(int i, int j) {
  18. clay = i;
  19. }
  20. public T() {
  21. this(clay, //ERROR static reference to instance field
  22. getJ()); //ERROR static reference to instance method
  23. clay++;
  24. getJ();
  25. 1+1; //ERROR not a legal statement
  26. }
  27. }
  28. aspect TAspect {
  29. int T.clay = 0;
  30. void around (T tt):
  31. target(tt) && call(void printIt()) {
  32. T.clay = 1; // ERROR static reference to instance field
  33. T.getJ(); //ERROR static reference to instance method
  34. }
  35. }