Is there a way to have a parameter for a method be of type Method() somehow?
Okay, so I have restructured my program to work more efficiently with serialization and saving the files the way I want...but now I need to be able to deserialize the object and use it to get the Class's getter methods. So in my FileIO class I have created a serialize() method, and a few deSerialize() methods with parameters to meet the needs of my program...minus one that would help tremendously. So, here is an example of what I want to do...but it doesn't work with the way I have it setup...I don't even know if it's possible so if it is how would I write the parameter??
Code:
public void deSerialize( String pFileName, Cabinet pObject, JTextField txf, Method pMethod )
{ // my question is about this parameter ^^^^^^^^^^^^^^
try
{
Cabinet cabinet;
File file = new File( pFileName + ".dat" );
FileInputStream inStream = new FileInputStream( file );
ObjectInputStream objectInputFile = new ObjectInputStream( inStream );
cabinet = ( Cabinet ) objectInputFile.readObject();
txf.setText( String.valueOf( cabinet.pMethod() ) );
// This is where the parameter needs to be ^, otherwise I have to make one of these methods for each
// method call I want and just write the method in there without it being a variable.
inStream.close();
objectInputFile.close();
}
catch( FileNotFoundException e )
{
}
catch( IOException e )
{
}
catch( ClassNotFoundException e )
{
}
}
Re: Is there a way to have a parameter for a method be of type Method() somehow?
Read the API doc for the Method class.
The parameter variable: pMethod is an instance of Method. It is not the name of a method in a class.
To call the method represented by this variable is different than the way you are trying to do it.
Re: Is there a way to have a parameter for a method be of type Method() somehow?
I just used that as an example, that is my question. What do I replace Method with to make pMethod work?
Re: Is there a way to have a parameter for a method be of type Method() somehow?
Create an interface with pMethod() defined.
Have the classes that you want to pass to the deSerialize() method implement that method.