Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » StackOverflowError when calling super in override dispatch method
StackOverflowError when calling super in override dispatch method [message #1782864] Fri, 02 March 2018 16:26 Go to next message
Jürgen  ing is currently offline Jürgen ingFriend
Messages: 8
Registered: July 2009
Junior Member
Hi,

I have two classes. Class B extends class A like this:

class A {
  def dispatch String doA(Object a) {}
  def dispatch String doA(String a) {}
}

class B extends A {
  override dispatch String doA(String a) {
    if (a.isEmpty)
      "empty"
    else
      super.doA(a)
  }
}


When I call new B().doA("123") I get an StackOverflowError. I just want to extend the behavior of doA in B and delegate the default to the super class. Any idea how to solve this?
Re: StackOverflowError when calling super in override dispatch method [message #1782866 is a reply to message #1782864] Fri, 02 March 2018 16:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
you can override a single dispatch case like

class B extends A {
  override dispatch String doA(String a) {
    if (a.isEmpty)
      "empty"
    else
      super._doA(a)
  }
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: StackOverflowError when calling super in override dispatch method [message #1783339 is a reply to message #1782866] Mon, 12 March 2018 08:40 Go to previous messageGo to next message
Jürgen  ing is currently offline Jürgen ingFriend
Messages: 8
Registered: July 2009
Junior Member
This solved my problem. Thank you.

One question. Calling super.doA(a) in a override dispatch method is always an error?
Re: StackOverflowError when calling super in override dispatch method [message #1783340 is a reply to message #1783339] Mon, 12 March 2018 08:50 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
calling super in general not, calling on the same parameter likely

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:LSP: resolving types
Next Topic:Xtext using Xbase
Goto Forum:
  


Current Time: Thu Sep 26 02:53:42 GMT 2024

Powered by FUDForum. Page generated in 0.03652 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top