This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing Method address?

 
Mike Dever
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic