This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Passing Method address? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Passing Method address?" Watch "Passing Method address?" New topic
Author

Passing Method address?

Mike Dever
Greenhorn

Joined: May 02, 2005
Posts: 1
Is it possible to pass in a class.Method address to a class..
I find I'm writing the same boilerplate code over and over only because
I have to specify the the method name inside the code:

If I could build a method that could take a method address,
then I could put this code into a method:

possible method:
void myTemplateMethod( MethodAddress dmd.GetMaxSchemaNameLenght, bool bHtmlOutput )
{
}


try
{
nMaxSchemaNameLength = dmd.getMaxSchemaNameLength();
if( nMaxSchemaNameLength == 0 )
{
sSchemaNameLength = "No Limit or Limit Unknown";
}
else
{
sSchemaNameLength = Integer.toString( nMaxSchemaNameLength );
}

if( bHtml )
{
sb.append( buildRow( descMaxSchemaNameLength, sSchemaNameLength, bRowColor ) );
}
else
{
sb.append( descMaxSchemaNameLength + " : " + sSchemaNameLength + crlf );
}
bRowColor = ( !bRowColor );
}
catch( SQLException se )
{
String sError = "Sql Error: " + se.getErrorCode() + se.getMessage() + se.toString();
if( bHtml )
{
sb.append( buildRow( descMaxSchemaNameLength + ": " + sNA, sError, bRowColor ) );
}
else
{
sb.append( sError + crlf );
}
}
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
There's no such thing as a method "pointer" in Java. You could pass the Method object, but you would have to make sure you also pass the instance on which it is to be called. Alternatively, you could use OGNL.


James Carman, President<br />Carman Consulting, Inc.
 
Consider Paul's rocket mass heater.
 
subject: Passing Method address?
 
Similar Threads
jaxb be converting bean to xml
HttpURLConnection - Posting XML to a servlet
JSF and generating a long GET request with REST
string and string buffer
String, read and write file problem...