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

Way of Calling a method

 
Nilesh Srivastava
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
objName.methodcall(Param pObj(){})
Where objName is Object Name
methodcall is Method Name
Param pObj() is a parameter passed as object refence.
There are two(opening and closing)curly braces after pObj(){}
Just let me know whether this way of calling any method is correct.
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
I'm not sure what you're asking. What you've written above is not correct Java syntax, in any context; but I'm not sure if it's supposed to be, or if it's supposed to be pseudocode.
If this was in the beginners's forum, I'd explain something about calling methods in general. But since this is the intermediate forum, I'll assume you're asking a harder question, and I just don't understand what it is. Can you restate the question in a different way?
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the normal way of calling a method:
objName.methodcall(Param pObj)
When you call a method you normally just pass in a reference to an object of type Param. The acutal code would look like:
1)Param pObj = new Param(); //create object
objName.methodcall(pObj); //pass object to method
The only reason you would have parenthesis () included would be to indicate that you were calling method instead of naming a variable which is a reference. If you are saying that you intend to call a method and that method will return an object of type Param you might use that syntax, but that is much less common than the syntax above.
2) objName.methodcall(this.diffmethod()); //diffmethod returns an object of type Param
The only reason that you would ever have curly braces in the parameter of a method call would be if you are declaring an anonymous class and instantiating it at the same time, and that instance is the parameter into the methodcall.
3) objName.methodcall(new someInterface(){public void someAction(SomeParam e){//do something}});
Is that what you were asking?
 
Nilesh Srivastava
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Thanks u all for replying to my post.Specially Cindy, U answered my question.Actually ur 3rd part is my answer and to which I was looking forward.
I was not sure whether we can give curly braces in a method call.
Thanks again to all of u.
If there can be any more suggestions or posts on this ..please go ahead as I really want to know much more about this.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic