File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 24166
    
  30



[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: 24166
    
  30

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();
 
Don't get me started about those stupid light bulbs.
 
subject: static methods: A.initilize().getValue(x);
 
Similar Threads
forward referencing
Member inner class
simple prog.
Using a variable before it has been initialised
Private modifier problem