• Post Reply Bookmark Topic Watch Topic
  • New Topic

Message passing in classes/member var  RSS feed

 
Santosh Maskar
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class A {
public boolean gridLines;

public void setGridLines(boolean val) {
gridLines = val;
Viewer.setGridLines(gridLines);
}
}


Class B {
A aArr[];
...
A getA(int index) {
return aArr[index];
}
}

Class C {
B.getA(0).gridLines = false;
}

after the line in class C gets called SetGridLines in class A should get called.

is there any way to achive this??
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Santosh Maskar:
Class A {
public boolean gridLines;

public void setGridLines(boolean val) {
gridLines = val;
Viewer.setGridLines(gridLines);
}
}


Class B {
A aArr[];
...
A getA(int index) {
return aArr[index];
}
}

Class C {
B.getA(0).gridLines = false;
}

after the line in class C gets called SetGridLines in class A should get called.

is there any way to achive this??



Does your code compile? The compiler might say something like non-static method getA cannot be called in a static context.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compiler would say all kinds of things, but I think this is really just pseudocode.

The poster wants to know if there's a way to make

x.foo = false;

automatically call

a.setFoo(false);

and the answer is unequivocally no, not in Java. Method calls always look like method calls.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!