Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Passing Method address?
 
Similar Threads
JSF and generating a long GET request with REST
String, read and write file problem...
jaxb be converting bean to xml
HttpURLConnection - Posting XML to a servlet
string and string buffer