Is it possible to invoke “super” with less ambiguous results?SFDC: Understanding With Sharing, Without...
How did J. J. Thomson establish the particle nature of the electron?
Do Australia and New Zealand have a travel ban on Somalis (like Wikipedia says)?
How can I automate this tensor computation?
Why isn't a binary file shown as 0s and 1s?
Is it possible to have a career in SciComp without contributing to arms research?
Is it possible to invoke "super" with less ambiguous results?
How to belay quickly ascending top-rope climbers?
How to interpret a promising preprint that was never published in peer-review?
How did Jayne know when to shoot?
Is this Android phone Android 9.0 or Android 6.0?
Batch processing/extracting raw data of one raster using one shapefile (with many polygons)?
Why is Google approaching my VPS machine?
Who would use the word "manky"?
What is the name for the average of the largest and the smallest values in a given data set?
Applying for jobs with an obvious scar
Don't individual signal sources affect each other when using a summing amplifier?
Why can't I hear fret buzz through the amp?
What would be the safest way to drop thousands of small, hard objects from a typical, high wing, GA airplane?
When will the last unambiguous evidence of mankind disappear?
Changing iteration variable in Do loop
Proof that every field is perfect???
Diagram of Methods to Solve Differential Equations
Locked-up DOS computer beeped on keypress. What mechanism caused that?
Improving an O(N^2) function (all entities iterating over all other entities)
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;
}
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
add a comment |
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
1
isSomeDependency 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
add a comment |
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
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
apex inheritance parent abstract
edited 7 hours ago
Pranay Jaiswal
22.4k5 gold badges33 silver badges73 bronze badges
22.4k5 gold badges33 silver badges73 bronze badges
asked 9 hours ago
Brian KesslerBrian Kessler
1,77513 silver badges34 bronze badges
1,77513 silver badges34 bronze badges
1
isSomeDependency 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
add a comment |
1
isSomeDependency 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
add a comment |
1 Answer
1
active
oldest
votes
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
edited 6 hours ago
answered 8 hours ago
Pranay JaiswalPranay Jaiswal
22.4k5 gold badges33 silver badges73 bronze badges
22.4k5 gold badges33 silver badges73 bronze badges
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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