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?

Desktop app status bar: Notification vs error message

Should I accept an invitation to give a talk from someone who might review my proposal?

What is the German equivalent of the proverb 水清ければ魚棲まず (if the water is clear, fish won't live there)?

Why were contact sensors put on three of the Lunar Module's four legs? Did they ever bend and stick out sideways?

What clothes would flying-people wear?

GNU GPL V3 with no code change disclosure

Do the books ever say oliphaunts aren’t elephants?

Do 3/8 (37.5%) of Quadratics Have No x-Intercepts?

Self-deportation of American Citizens from US

Trying to open a new ubuntu terminal window from the existing window

Why does aggregate initialization not work anymore since C++20 if a constructor is explicitly defaulted or deleted?

How to store my pliers and wire cutters on my desk?

In syntax, why cannot we say things like "he took walked at the park"? but can say "he took a walk at the park"?

Blank spaces in a font

Why does the Eurostar not show youth pricing?

Why was the LRV's speed gauge displaying metric units?

If the Moon were impacted by a suitably sized meteor, how long would it take to impact the Earth?

Is it safe if the neutral lead is exposed and disconnected?

A variant of the Multiple Traveling Salesman Problem

Would people understand me speaking German all over Europe?

Nuclear breeder/reactor plant controlled by two A.I. makes too much power

Surviving a planet collision?

Semen retention is a important thing in Martial arts?

Should I intervene when a colleague in a different department makes students run laps as part of their grade?



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;








6















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 void 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
    Jul 19 at 16:32











  • 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
    Jul 19 at 16:42











  • have you tried raising a case with SF?

    – Pranay Jaiswal
    Jul 19 at 18:55











  • Interesting, in the docs for super it says "You can only use super in methods that are designated with the override keyword.". That doesn't seem to be the case here.

    – Daniel Ballinger
    Jul 23 at 22:12

















6















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 void 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
    Jul 19 at 16:32











  • 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
    Jul 19 at 16:42











  • have you tried raising a case with SF?

    – Pranay Jaiswal
    Jul 19 at 18:55











  • Interesting, in the docs for super it says "You can only use super in methods that are designated with the override keyword.". That doesn't seem to be the case here.

    – Daniel Ballinger
    Jul 23 at 22:12













6












6








6


3






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 void 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 void 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 Jul 26 at 13:48









Pranay Jaiswal

22.8k5 gold badges33 silver badges74 bronze badges




22.8k5 gold badges33 silver badges74 bronze badges










asked Jul 19 at 16:05









Brian KesslerBrian Kessler

1,80613 silver badges35 bronze badges




1,80613 silver badges35 bronze badges










  • 1





    is SomeDependency someDependency; protected?#

    – Pranay Jaiswal
    Jul 19 at 16:32











  • 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
    Jul 19 at 16:42











  • have you tried raising a case with SF?

    – Pranay Jaiswal
    Jul 19 at 18:55











  • Interesting, in the docs for super it says "You can only use super in methods that are designated with the override keyword.". That doesn't seem to be the case here.

    – Daniel Ballinger
    Jul 23 at 22:12












  • 1





    is SomeDependency someDependency; protected?#

    – Pranay Jaiswal
    Jul 19 at 16:32











  • 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
    Jul 19 at 16:42











  • have you tried raising a case with SF?

    – Pranay Jaiswal
    Jul 19 at 18:55











  • Interesting, in the docs for super it says "You can only use super in methods that are designated with the override keyword.". That doesn't seem to be the case here.

    – Daniel Ballinger
    Jul 23 at 22:12







1




1





is SomeDependency someDependency; protected?#

– Pranay Jaiswal
Jul 19 at 16:32





is SomeDependency someDependency; protected?#

– Pranay Jaiswal
Jul 19 at 16:32













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
Jul 19 at 16:42





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
Jul 19 at 16:42













have you tried raising a case with SF?

– Pranay Jaiswal
Jul 19 at 18:55





have you tried raising a case with SF?

– Pranay Jaiswal
Jul 19 at 18:55













Interesting, in the docs for super it says "You can only use super in methods that are designated with the override keyword.". That doesn't seem to be the case here.

– Daniel Ballinger
Jul 23 at 22:12





Interesting, in the docs for super it says "You can only use super in methods that are designated with the override keyword.". That doesn't seem to be the case here.

– Daniel Ballinger
Jul 23 at 22:12










1 Answer
1






active

oldest

votes


















9














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



























  • I would have expected the normal order of operations to "calculate" super.someDependency first even with the parenthesis. ... Cheers to you and Anshul for figuring out that this will work. :-)

    – Brian Kessler
    Jul 20 at 8:45













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









9














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



























  • I would have expected the normal order of operations to "calculate" super.someDependency first even with the parenthesis. ... Cheers to you and Anshul for figuring out that this will work. :-)

    – Brian Kessler
    Jul 20 at 8:45















9














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



























  • I would have expected the normal order of operations to "calculate" super.someDependency first even with the parenthesis. ... Cheers to you and Anshul for figuring out that this will work. :-)

    – Brian Kessler
    Jul 20 at 8:45













9












9








9







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 Jul 19 at 19:10

























answered Jul 19 at 16:58









Pranay JaiswalPranay Jaiswal

22.8k5 gold badges33 silver badges74 bronze badges




22.8k5 gold badges33 silver badges74 bronze badges















  • I would have expected the normal order of operations to "calculate" super.someDependency first even with the parenthesis. ... Cheers to you and Anshul for figuring out that this will work. :-)

    – Brian Kessler
    Jul 20 at 8:45

















  • I would have expected the normal order of operations to "calculate" super.someDependency first even with the parenthesis. ... Cheers to you and Anshul for figuring out that this will work. :-)

    – Brian Kessler
    Jul 20 at 8:45
















I would have expected the normal order of operations to "calculate" super.someDependency first even with the parenthesis. ... Cheers to you and Anshul for figuring out that this will work. :-)

– Brian Kessler
Jul 20 at 8:45





I would have expected the normal order of operations to "calculate" super.someDependency first even with the parenthesis. ... Cheers to you and Anshul for figuring out that this will work. :-)

– Brian Kessler
Jul 20 at 8:45

















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

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?