• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Message passing in classes/member var

 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Legend has it that if you rub the right tiny ad, a genie comes out.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic