Groovy web console

subscribe to the feed Subscribe
to this
site
casting extended to base (via #groovywebconsole)
tweet this snippet Tweet
this
script

casting extended to base

Published 6 months ago by codifies
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
class base {
    String name = null
    base(Name) { name=Name }
    def sayHello() { println "hello from "+name }
}

class extended extends base {
    def extended(String s) { super(s) }
    def sayHello() { println "hello extended from "+name }
}


def b = base.newInstance("bert")
b.sayHello()
        
def e = extended.newInstance("fred")
def f = extended.newInstance("bill")
e.sayHello()

f.sayHello()
def fb = (base)f
// def fb = f.asType(base)
println "fb class = " + fb.getClass()
fb.sayHello()