function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Saurabh AgrahariSaurabh Agrahari 

Forward Referencing

Does Apex allows forward referencing?
Andy BoettcherAndy Boettcher
I don't believe so.  What are you trying to do?
Saurabh AgrahariSaurabh Agrahari
Thanks for the reply Andy,

Actually I was trying to write some thing like ,

public with sharing class Forward_ref
{
        call_before_declaration();
        public  void  call_before_declaration()
                 {
                        System.debug("before declaration");
                 }
}
It gave me the error "Method must define a body".

However I corrected the error as mentioned below,

public with sharing class Forward_ref
{
public void call_method()
    {
          call_before_declaration();
   }
  public void call_before_declaration()
        {
           System.debug('Forward declaration');
        }
                
}

So it looks like this a way it works in apex,

And looks to me that I have used the wrong term for this they call it "Forward declaration" in apex not "forward referencing".

Please add further if i missed something to build the concept .


Thanks
Saurabh Agrahari