Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static methods: A.initilize().getValue(x);

 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers
Say I have a class A
how can I do this (in the void main)?

int i = A.initilize().getValue(x);

thanks
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks but I'm looking for the code to do this:
A.initilize().getValue(x)

just like:


String str ="somthing like this ";

int x = str.trim().length();
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you can't do that because initialize() returns void (of course). For that to work, initialize() would have to return an instance of A. This would be kind of silly, as the instance wouldn't be used; furthermore, many IDEs would warn about the usage.

It's never occurred to be as a general rule before, but it's obvious that in fact static method calls can't be chained together.
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


RIGHT!!!

ok...I can do this: private all methods and have one method public as:

public static int getMyValue()
{
A.initilize();
return A.getValue();
}

so in void main: A.getMyValue();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic