Groovy web console

subscribe to the feed Subscribe
to this
site

duck typing

Published 1 month ago by brakeley
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
class Foo {
    def show(str) {
        println('--- Foo [' + str.getClass() + ']: ' + str)
    }
}

class Bar extends Foo {
    def show(String str) {
        println('=== Bar [' + str.getClass() + ']: ' + str)
    }
}

Foo a= new Foo();
int n = 8;
a.show(n);
a.show("${n}");


Foo b= new Bar();
int m = 13;
b.show(m);
b.show("${m}");