Results 1 to 4 of 4
  1. #1
    Tombomb is offline Member
    Join Date
    Jan 2012
    Posts
    33
    Rep Power
    0

    Question 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??

    Java 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 )
          {
             
          }
       }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,412
    Rep Power
    25

    Default 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.

  3. #3
    Tombomb is offline Member
    Join Date
    Jan 2012
    Posts
    33
    Rep Power
    0

    Default 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?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,412
    Rep Power
    25

    Default 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.

Similar Threads

  1. url parameter in open method used in ajax
    By pulkit.sharva in forum New To Java
    Replies: 0
    Last Post: 01-14-2012, 07:08 AM
  2. Get method parameter values using AspectJ?
    By gonny in forum New To Java
    Replies: 0
    Last Post: 11-21-2011, 09:16 AM
  3. Replies: 18
    Last Post: 04-18-2011, 05:39 AM
  4. Class<T> in method parameter
    By Onra in forum New To Java
    Replies: 4
    Last Post: 03-14-2011, 12:12 AM
  5. Can a method take itself as parameter?
    By bukake in forum New To Java
    Replies: 10
    Last Post: 09-06-2008, 09:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •