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: 12029
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)
  }
}


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
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: 12029
Registered: July 2009
Senior Member
calling super in general not, calling on the same parameter likely

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:LSP: resolving types
Next Topic:Xtext using Xbase
Goto Forum:
  


Current Time: Wed Jun 20 05:40:03 GMT 2018

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

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

Back to the top