*
The moose likes Beginning Java and the fly likes static methods: A.initilize().getValue(x); Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "static methods: A.initilize().getValue(x);" Watch "static methods: A.initilize().getValue(x);" New topic
Author

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

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
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

Joined: Jul 08, 2003
Posts: 24183
    
  34



[Jess in Action][AskingGoodQuestions]
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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

Joined: Sep 10, 2004
Posts: 755


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();
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: static methods: A.initilize().getValue(x);
 
Similar Threads
Member inner class
simple prog.
Private modifier problem
Using a variable before it has been initialised
forward referencing