Is it possible to invoke “super” with less ambiguous results?SFDC: Understanding With Sharing, Without Sharing & Unspecified Sharing ClassesMaximum stack depth reached: 1001Could private method be overriden in the inheritance hierarchy?How to pass a variable's value of child visualforce page to a variable in parent visualforce using jsextend a class that implement Messaging.InboundEmailHandler (email service)Problem using Protected modifier to expose method to inner classIssue linking two classes togetherUnexpected constructor execution with subclasses - bug?Accessing public class from different Package in same NamespaceHow does object inheritance interact with sharing inheritance?

Do pedestrians imitate auto traffic?

Wait or be waiting?

When designing an adventure, how can I ensure a continuous player experience in a setting that's likely to favor TPKs?

What's a German word for »Sandbagger«?

Who or what determines if a curse is valid or not?

Locked-up DOS computer beeped on keypress. What mechanism caused that?

Why is Google approaching my VPS machine?

literal `0` beeing a valid candidate for int and const string& overloads causes ambiguous call

Why does a tetrahedral molecule like methane have a dipole moment of zero?

"Je suis petite, moi?", purpose of the "moi"?

How to tell if JDK is available from within running JVM?

Demographic consequences of closed loop reincarnation

How important are the Author's mood and feelings for writing a story?

Why do space operations use "nominal" to mean "working correctly"?

Real orthogonal and sign

How did J. J. Thomson establish the particle nature of the electron?

How to extract interesting piece of output in bash

Does 5e follow the Primary Source rule?

Is this Android phone Android 9.0 or Android 6.0?

I have found a mistake on someone's code published online: what is the protocol?

Why is the Intel 8086 CPU called a 16-bit CPU?

How long were the Apollo astronauts allowed to breathe 100% oxygen at 1 atmosphere continuously?

May I use a railway velocipede on actively-used British railways?

When will the last unambiguous evidence of mankind disappear?



Is it possible to invoke “super” with less ambiguous results?


SFDC: Understanding With Sharing, Without Sharing & Unspecified Sharing ClassesMaximum stack depth reached: 1001Could private method be overriden in the inheritance hierarchy?How to pass a variable's value of child visualforce page to a variable in parent visualforce using jsextend a class that implement Messaging.InboundEmailHandler (email service)Problem using Protected modifier to expose method to inner classIssue linking two classes togetherUnexpected constructor execution with subclasses - bug?Accessing public class from different Package in same NamespaceHow does object inheritance interact with sharing inheritance?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








4















I have an abstract parent class with some dependency and a default implementation.
The constructors might look like:



 public abstract class ParentClass 
protected SomeDependency someDependency;

public ParentClass(SomeDependency someDependency)
this.someDependency = someDependency;






The dependency itself is a virtual class with methods that might be overridden, for example:



public virtual class SomeDependency 
public virtual void doSomething()
System.debug('#### SomeDependency');




The dependency has an extension:



public class ChildDependency extends SomeDependency 
public override void doSomething()
System.debug('#### ChildDependency ');




And the child of the original abstract parent looks like this:



public class ChildClass extends ParentClass 
public ChildClass()
super(new ChildDependency());


public doSomething()
super.someDependency.doSomething();




In this context, I intended that "super" means that "someDependency" lives on the Parent instead of the current object.



However, when I execute this code, I get:




SomeDependency


Which tells me the code is actually interpreting this to mean the parent of ChildDependency.



If I change super.someDependency.doSomething(); to this.someDependency.doSomething();



the code works as I originally expected it to, BUT now the code is "lying" to me because someDependency is actually an instance which lives on the parent and I'd like to make that obvious in my code.



Is there a way I can make my code express this properly?










share|improve this question



















  • 1





    is SomeDependency someDependency; protected?#

    – Pranay Jaiswal
    8 hours ago











  • This sounds so weird, ideally the method should be called for the instance that was present. If childDependency instance was passed child method should have been called

    – Pranay Jaiswal
    8 hours ago











  • have you tried raising a case with SF?

    – Pranay Jaiswal
    6 hours ago

















4















I have an abstract parent class with some dependency and a default implementation.
The constructors might look like:



 public abstract class ParentClass 
protected SomeDependency someDependency;

public ParentClass(SomeDependency someDependency)
this.someDependency = someDependency;






The dependency itself is a virtual class with methods that might be overridden, for example:



public virtual class SomeDependency 
public virtual void doSomething()
System.debug('#### SomeDependency');




The dependency has an extension:



public class ChildDependency extends SomeDependency 
public override void doSomething()
System.debug('#### ChildDependency ');




And the child of the original abstract parent looks like this:



public class ChildClass extends ParentClass 
public ChildClass()
super(new ChildDependency());


public doSomething()
super.someDependency.doSomething();




In this context, I intended that "super" means that "someDependency" lives on the Parent instead of the current object.



However, when I execute this code, I get:




SomeDependency


Which tells me the code is actually interpreting this to mean the parent of ChildDependency.



If I change super.someDependency.doSomething(); to this.someDependency.doSomething();



the code works as I originally expected it to, BUT now the code is "lying" to me because someDependency is actually an instance which lives on the parent and I'd like to make that obvious in my code.



Is there a way I can make my code express this properly?










share|improve this question



















  • 1





    is SomeDependency someDependency; protected?#

    – Pranay Jaiswal
    8 hours ago











  • This sounds so weird, ideally the method should be called for the instance that was present. If childDependency instance was passed child method should have been called

    – Pranay Jaiswal
    8 hours ago











  • have you tried raising a case with SF?

    – Pranay Jaiswal
    6 hours ago













4












4








4


2






I have an abstract parent class with some dependency and a default implementation.
The constructors might look like:



 public abstract class ParentClass 
protected SomeDependency someDependency;

public ParentClass(SomeDependency someDependency)
this.someDependency = someDependency;






The dependency itself is a virtual class with methods that might be overridden, for example:



public virtual class SomeDependency 
public virtual void doSomething()
System.debug('#### SomeDependency');




The dependency has an extension:



public class ChildDependency extends SomeDependency 
public override void doSomething()
System.debug('#### ChildDependency ');




And the child of the original abstract parent looks like this:



public class ChildClass extends ParentClass 
public ChildClass()
super(new ChildDependency());


public doSomething()
super.someDependency.doSomething();




In this context, I intended that "super" means that "someDependency" lives on the Parent instead of the current object.



However, when I execute this code, I get:




SomeDependency


Which tells me the code is actually interpreting this to mean the parent of ChildDependency.



If I change super.someDependency.doSomething(); to this.someDependency.doSomething();



the code works as I originally expected it to, BUT now the code is "lying" to me because someDependency is actually an instance which lives on the parent and I'd like to make that obvious in my code.



Is there a way I can make my code express this properly?










share|improve this question
















I have an abstract parent class with some dependency and a default implementation.
The constructors might look like:



 public abstract class ParentClass 
protected SomeDependency someDependency;

public ParentClass(SomeDependency someDependency)
this.someDependency = someDependency;






The dependency itself is a virtual class with methods that might be overridden, for example:



public virtual class SomeDependency 
public virtual void doSomething()
System.debug('#### SomeDependency');




The dependency has an extension:



public class ChildDependency extends SomeDependency 
public override void doSomething()
System.debug('#### ChildDependency ');




And the child of the original abstract parent looks like this:



public class ChildClass extends ParentClass 
public ChildClass()
super(new ChildDependency());


public doSomething()
super.someDependency.doSomething();




In this context, I intended that "super" means that "someDependency" lives on the Parent instead of the current object.



However, when I execute this code, I get:




SomeDependency


Which tells me the code is actually interpreting this to mean the parent of ChildDependency.



If I change super.someDependency.doSomething(); to this.someDependency.doSomething();



the code works as I originally expected it to, BUT now the code is "lying" to me because someDependency is actually an instance which lives on the parent and I'd like to make that obvious in my code.



Is there a way I can make my code express this properly?







apex inheritance parent abstract






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 7 hours ago









Pranay Jaiswal

22.4k5 gold badges33 silver badges73 bronze badges




22.4k5 gold badges33 silver badges73 bronze badges










asked 8 hours ago









Brian KesslerBrian Kessler

1,77513 silver badges34 bronze badges




1,77513 silver badges34 bronze badges







  • 1





    is SomeDependency someDependency; protected?#

    – Pranay Jaiswal
    8 hours ago











  • This sounds so weird, ideally the method should be called for the instance that was present. If childDependency instance was passed child method should have been called

    – Pranay Jaiswal
    8 hours ago











  • have you tried raising a case with SF?

    – Pranay Jaiswal
    6 hours ago












  • 1





    is SomeDependency someDependency; protected?#

    – Pranay Jaiswal
    8 hours ago











  • This sounds so weird, ideally the method should be called for the instance that was present. If childDependency instance was passed child method should have been called

    – Pranay Jaiswal
    8 hours ago











  • have you tried raising a case with SF?

    – Pranay Jaiswal
    6 hours ago







1




1





is SomeDependency someDependency; protected?#

– Pranay Jaiswal
8 hours ago





is SomeDependency someDependency; protected?#

– Pranay Jaiswal
8 hours ago













This sounds so weird, ideally the method should be called for the instance that was present. If childDependency instance was passed child method should have been called

– Pranay Jaiswal
8 hours ago





This sounds so weird, ideally the method should be called for the instance that was present. If childDependency instance was passed child method should have been called

– Pranay Jaiswal
8 hours ago













have you tried raising a case with SF?

– Pranay Jaiswal
6 hours ago





have you tried raising a case with SF?

– Pranay Jaiswal
6 hours ago










1 Answer
1






active

oldest

votes


















4














Sounds a bug to me, the instance is still of ChildDependency I confirmed it using debug logs.



public class ChildClass extends ParentClass 
public ChildClass()
super(new ChildDependency());


public void doSomething()
System.debug( this.someDependency);
System.debug( super.someDependency);
this.someDependency.doSomething();
super.someDependency.doSomething();




Execute Anon : new ChildClass().doSomething();



DEUBG:



17:53:16.60 (131753925)|USER_DEBUG|[7]|DEBUG|ChildDependency:[]
17:53:16.60 (131775245)|USER_DEBUG|[8]|DEBUG|ChildDependency:[]
17:53:16.60 (131813593)|USER_DEBUG|[4]|DEBUG|#### ChildDependency
17:53:16.60 (131834856)|USER_DEBUG|[4]|DEBUG|#### SomeDependency


Edit 1: I replicated the same behavior in Java in case anyone wanna do it and its behaving as expected.
Java Code demo : https://repl.it/repls/SmugFlawlessUnderstanding



I have a feeling Salesforce Apex Engine uses Java Reflection Like engine to call Apex Methods instead of running Compiled Apex Natively on their servers.



Edit 2: A friend of mine(Thanks Anshul) managed to get it to work by using some unique Syntax.



public class ChildClass extends ParentClass 

public ChildClass()
super(new ChildDependency());


public void doSomething()
System.debug( this.someDependency);
System.debug( super.someDependency);
this.someDependency.doSomething();
(super.someDependency).doSomething();




Yes , (super.someDependency).doSomething(); makes code do what it's supposed to do. Now I wonder if Salesforce uses String parsing to determine keywords and then run Apex code.






share|improve this answer



























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "459"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f270181%2fis-it-possible-to-invoke-super-with-less-ambiguous-results%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4














    Sounds a bug to me, the instance is still of ChildDependency I confirmed it using debug logs.



    public class ChildClass extends ParentClass 
    public ChildClass()
    super(new ChildDependency());


    public void doSomething()
    System.debug( this.someDependency);
    System.debug( super.someDependency);
    this.someDependency.doSomething();
    super.someDependency.doSomething();




    Execute Anon : new ChildClass().doSomething();



    DEUBG:



    17:53:16.60 (131753925)|USER_DEBUG|[7]|DEBUG|ChildDependency:[]
    17:53:16.60 (131775245)|USER_DEBUG|[8]|DEBUG|ChildDependency:[]
    17:53:16.60 (131813593)|USER_DEBUG|[4]|DEBUG|#### ChildDependency
    17:53:16.60 (131834856)|USER_DEBUG|[4]|DEBUG|#### SomeDependency


    Edit 1: I replicated the same behavior in Java in case anyone wanna do it and its behaving as expected.
    Java Code demo : https://repl.it/repls/SmugFlawlessUnderstanding



    I have a feeling Salesforce Apex Engine uses Java Reflection Like engine to call Apex Methods instead of running Compiled Apex Natively on their servers.



    Edit 2: A friend of mine(Thanks Anshul) managed to get it to work by using some unique Syntax.



    public class ChildClass extends ParentClass 

    public ChildClass()
    super(new ChildDependency());


    public void doSomething()
    System.debug( this.someDependency);
    System.debug( super.someDependency);
    this.someDependency.doSomething();
    (super.someDependency).doSomething();




    Yes , (super.someDependency).doSomething(); makes code do what it's supposed to do. Now I wonder if Salesforce uses String parsing to determine keywords and then run Apex code.






    share|improve this answer





























      4














      Sounds a bug to me, the instance is still of ChildDependency I confirmed it using debug logs.



      public class ChildClass extends ParentClass 
      public ChildClass()
      super(new ChildDependency());


      public void doSomething()
      System.debug( this.someDependency);
      System.debug( super.someDependency);
      this.someDependency.doSomething();
      super.someDependency.doSomething();




      Execute Anon : new ChildClass().doSomething();



      DEUBG:



      17:53:16.60 (131753925)|USER_DEBUG|[7]|DEBUG|ChildDependency:[]
      17:53:16.60 (131775245)|USER_DEBUG|[8]|DEBUG|ChildDependency:[]
      17:53:16.60 (131813593)|USER_DEBUG|[4]|DEBUG|#### ChildDependency
      17:53:16.60 (131834856)|USER_DEBUG|[4]|DEBUG|#### SomeDependency


      Edit 1: I replicated the same behavior in Java in case anyone wanna do it and its behaving as expected.
      Java Code demo : https://repl.it/repls/SmugFlawlessUnderstanding



      I have a feeling Salesforce Apex Engine uses Java Reflection Like engine to call Apex Methods instead of running Compiled Apex Natively on their servers.



      Edit 2: A friend of mine(Thanks Anshul) managed to get it to work by using some unique Syntax.



      public class ChildClass extends ParentClass 

      public ChildClass()
      super(new ChildDependency());


      public void doSomething()
      System.debug( this.someDependency);
      System.debug( super.someDependency);
      this.someDependency.doSomething();
      (super.someDependency).doSomething();




      Yes , (super.someDependency).doSomething(); makes code do what it's supposed to do. Now I wonder if Salesforce uses String parsing to determine keywords and then run Apex code.






      share|improve this answer



























        4












        4








        4







        Sounds a bug to me, the instance is still of ChildDependency I confirmed it using debug logs.



        public class ChildClass extends ParentClass 
        public ChildClass()
        super(new ChildDependency());


        public void doSomething()
        System.debug( this.someDependency);
        System.debug( super.someDependency);
        this.someDependency.doSomething();
        super.someDependency.doSomething();




        Execute Anon : new ChildClass().doSomething();



        DEUBG:



        17:53:16.60 (131753925)|USER_DEBUG|[7]|DEBUG|ChildDependency:[]
        17:53:16.60 (131775245)|USER_DEBUG|[8]|DEBUG|ChildDependency:[]
        17:53:16.60 (131813593)|USER_DEBUG|[4]|DEBUG|#### ChildDependency
        17:53:16.60 (131834856)|USER_DEBUG|[4]|DEBUG|#### SomeDependency


        Edit 1: I replicated the same behavior in Java in case anyone wanna do it and its behaving as expected.
        Java Code demo : https://repl.it/repls/SmugFlawlessUnderstanding



        I have a feeling Salesforce Apex Engine uses Java Reflection Like engine to call Apex Methods instead of running Compiled Apex Natively on their servers.



        Edit 2: A friend of mine(Thanks Anshul) managed to get it to work by using some unique Syntax.



        public class ChildClass extends ParentClass 

        public ChildClass()
        super(new ChildDependency());


        public void doSomething()
        System.debug( this.someDependency);
        System.debug( super.someDependency);
        this.someDependency.doSomething();
        (super.someDependency).doSomething();




        Yes , (super.someDependency).doSomething(); makes code do what it's supposed to do. Now I wonder if Salesforce uses String parsing to determine keywords and then run Apex code.






        share|improve this answer















        Sounds a bug to me, the instance is still of ChildDependency I confirmed it using debug logs.



        public class ChildClass extends ParentClass 
        public ChildClass()
        super(new ChildDependency());


        public void doSomething()
        System.debug( this.someDependency);
        System.debug( super.someDependency);
        this.someDependency.doSomething();
        super.someDependency.doSomething();




        Execute Anon : new ChildClass().doSomething();



        DEUBG:



        17:53:16.60 (131753925)|USER_DEBUG|[7]|DEBUG|ChildDependency:[]
        17:53:16.60 (131775245)|USER_DEBUG|[8]|DEBUG|ChildDependency:[]
        17:53:16.60 (131813593)|USER_DEBUG|[4]|DEBUG|#### ChildDependency
        17:53:16.60 (131834856)|USER_DEBUG|[4]|DEBUG|#### SomeDependency


        Edit 1: I replicated the same behavior in Java in case anyone wanna do it and its behaving as expected.
        Java Code demo : https://repl.it/repls/SmugFlawlessUnderstanding



        I have a feeling Salesforce Apex Engine uses Java Reflection Like engine to call Apex Methods instead of running Compiled Apex Natively on their servers.



        Edit 2: A friend of mine(Thanks Anshul) managed to get it to work by using some unique Syntax.



        public class ChildClass extends ParentClass 

        public ChildClass()
        super(new ChildDependency());


        public void doSomething()
        System.debug( this.someDependency);
        System.debug( super.someDependency);
        this.someDependency.doSomething();
        (super.someDependency).doSomething();




        Yes , (super.someDependency).doSomething(); makes code do what it's supposed to do. Now I wonder if Salesforce uses String parsing to determine keywords and then run Apex code.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 5 hours ago

























        answered 7 hours ago









        Pranay JaiswalPranay Jaiswal

        22.4k5 gold badges33 silver badges73 bronze badges




        22.4k5 gold badges33 silver badges73 bronze badges



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Salesforce Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f270181%2fis-it-possible-to-invoke-super-with-less-ambiguous-results%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

            Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

            199年 目錄 大件事 到箇年出世嗰人 到箇年死嗰人 節慶、風俗習慣 導覽選單